Skip to content

Commit c024a09

Browse files
KyrylRArvolear
andauthored
Add yield with value. Fix bug related to argsSize (#54)
* Added yield with value * Added tests for yield with value * Removed redundant payable * Updated versions * fixed comments * fixed linting --------- Co-authored-by: Artem Chystiakov <artem.ch31@gmail.com>
1 parent 971e858 commit c024a09

40 files changed

Lines changed: 717 additions & 715 deletions

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![npm](https://img.shields.io/npm/v/@dlsl/dev-modules.svg)](https://www.npmjs.com/package/@dlsl/dev-modules)
1+
[![npm](https://img.shields.io/npm/v/@dlsl/dev-modules.svg)](https://www.npmjs.com/package/@dlsl/dev-modules)
22
[![Coverage Status](https://codecov.io/gh/dl-solidity-library/dev-modules/graph/badge.svg)](https://codecov.io/gh/dl-solidity-library/dev-modules)
33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
[![GitPOAP Badge](https://public-api.gitpoap.io/v1/repo/dl-solidity-library/dev-modules/badge)](https://www.gitpoap.io/gh/dl-solidity-library/dev-modules)
@@ -7,14 +7,15 @@
77

88
**Elaborate solidity development modules library by DL.**
99

10-
The library consists of modules and utilities that are built with a help of [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.8.0) and go far beyond mediocre solidity.
10+
The library consists of modules and utilities that are built with a help of [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.9.2) and go far beyond mediocre solidity.
1111

1212
- Implementation of [**Contracts Registry**](https://eips.ethereum.org/EIPS/eip-6224) pattern
1313
- Versatile **RBAC** smart contract
1414
- Enhanced and simplified [**Diamond**](https://eips.ethereum.org/EIPS/eip-2535) pattern
1515
- Heap based priority queue library
1616
- Memory data structures (Vector)
17-
- Enhanced [**Incremental Merkle Tree**](https://github.com/runtimeverification/deposit-contract-verification/blob/master/deposit-contract-verification.pdf) data structure
17+
- Optimized [**Incremental Merkle Tree**](https://github.com/runtimeverification/deposit-contract-verification/blob/master/deposit-contract-verification.pdf) data structure
18+
- Novel **ReturnDataProxy** contract
1819
- Utilities to ease work with ERC20 decimals, arrays, and sets
1920

2021
## Overview

contracts/access-control/MerkleWhitelisted.sol

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ pragma solidity ^0.8.4;
44
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
55

66
/**
7-
* @notice The Whitelist Access Control module
7+
* @notice The Whitelist Access Control module
88
*
9-
* This is a simple abstract contract that implements whitelisting logic.
9+
* This is a simple abstract contract that implements whitelisting logic.
1010
*
11-
* The contract is based on a Merkle tree, which allows for the huge whitelists to be cheaply validated courtesy of
12-
* O(log(n)) tree complexity. The whitelist itself is stored in the tree leaves and only the root of the tree is saved on-chain.
11+
* The contract is based on a Merkle tree, which allows for the huge whitelists to be cheaply validated courtesy of
12+
* O(log(n)) tree complexity. The whitelist itself is stored in the tree leaves and only the root of the tree is saved on-chain.
1313
*
14-
* To validate the whitelist belonging, the tree leaf (the whitelist element) has to be computed and passed to the
15-
* "root-construction" function together with the corresponding tree branches. The function will then check the
16-
* roots equality. If the roots match, the element belongs to the whitelist.
14+
* To validate the whitelist belonging, the tree leaf (the whitelist element) has to be computed and passed to the
15+
* "root-construction" function together with the corresponding tree branches. The function will then check the
16+
* roots equality. If the roots match, the element belongs to the whitelist.
1717
*
18-
* Note: the branch nodes are sorted numerically.
18+
* Note: the branch nodes are sorted numerically.
1919
*/
2020
abstract contract MerkleWhitelisted {
2121
using MerkleProof for bytes32[];
@@ -36,10 +36,10 @@ abstract contract MerkleWhitelisted {
3636
}
3737

3838
/**
39-
* @notice The function to check if the leaf belongs to the Merkle tree
40-
* @param leaf_ the leaf to be checked
41-
* @param merkleProof_ the path from the leaf to the Merkle tree root
42-
* @return true if the leaf belongs to the Merkle tree, false otherwise
39+
* @notice The function to check if the leaf belongs to the Merkle tree
40+
* @param leaf_ the leaf to be checked
41+
* @param merkleProof_ the path from the leaf to the Merkle tree root
42+
* @return true if the leaf belongs to the Merkle tree, false otherwise
4343
*/
4444
function isWhitelisted(
4545
bytes32 leaf_,
@@ -49,10 +49,10 @@ abstract contract MerkleWhitelisted {
4949
}
5050

5151
/**
52-
* @notice The function to check if the user belongs to the Merkle tree
53-
* @param user_ the user to be checked
54-
* @param merkleProof_ the path from the user to the Merkle tree root
55-
* @return true if the user belongs to the Merkle tree, false otherwise
52+
* @notice The function to check if the user belongs to the Merkle tree
53+
* @param user_ the user to be checked
54+
* @param merkleProof_ the path from the user to the Merkle tree root
55+
* @return true if the user belongs to the Merkle tree, false otherwise
5656
*/
5757
function isWhitelistedUser(
5858
address user_,
@@ -62,16 +62,16 @@ abstract contract MerkleWhitelisted {
6262
}
6363

6464
/**
65-
* @notice The function to get the current Merkle root
66-
* @return the current Merkle root or zero bytes if it has not been set
65+
* @notice The function to get the current Merkle root
66+
* @return the current Merkle root or zero bytes if it has not been set
6767
*/
6868
function getMerkleRoot() public view returns (bytes32) {
6969
return _merkleRoot;
7070
}
7171

7272
/**
73-
* @notice The function that should be called from the child contract to set the Merkle root
74-
* @param merkleRoot_ the Merkle root to be set
73+
* @notice The function that should be called from the child contract to set the Merkle root
74+
* @param merkleRoot_ the Merkle root to be set
7575
*/
7676
function _setMerkleRoot(bytes32 merkleRoot_) internal {
7777
_merkleRoot = merkleRoot_;

contracts/access-control/MultiOwnable.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {TypeCaster} from "../libs/utils/TypeCaster.sol";
99
import {IMultiOwnable} from "../interfaces/access-control/IMultiOwnable.sol";
1010

1111
/**
12-
* @notice The MultiOwnable module
12+
* @notice The MultiOwnable module
1313
*
14-
* Contract module which provides a basic access control mechanism, where there is a list of
15-
* owner addresses those can be granted exclusive access to specific functions.
16-
* All owners are equal in their access, they can add new owners, also remove each other and themself.
14+
* Contract module which provides a basic access control mechanism, where there is a list of
15+
* owner addresses those can be granted exclusive access to specific functions.
16+
* All owners are equal in their access, they can add new owners, also remove each other and themself.
1717
*
18-
* By default, the owner account will be the one that deploys the contract.
18+
* By default, the owner account will be the one that deploys the contract.
1919
*
20-
* This module will make available the modifier `onlyOwner`, which can be applied
21-
* to your functions to restrict their use to the owners.
20+
* This module will make available the modifier `onlyOwner`, which can be applied
21+
* to your functions to restrict their use to the owners.
2222
*/
2323
abstract contract MultiOwnable is IMultiOwnable, Initializable {
2424
using EnumerableSet for EnumerableSet.AddressSet;

contracts/access-control/RBAC.sol

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import {SetHelper} from "../libs/arrays/SetHelper.sol";
1010
import {StringSet} from "../libs/data-structures/StringSet.sol";
1111

1212
/**
13-
* @notice The Role Based Access Control (RBAC) module
13+
* @notice The Role Based Access Control (RBAC) module
1414
*
15-
* This is advanced module that handles role management for huge systems. One can declare specific permissions
16-
* for specific resources (contracts) and aggregate them into roles for further assignment to users.
15+
* This is advanced module that handles role management for huge systems. One can declare specific permissions
16+
* for specific resources (contracts) and aggregate them into roles for further assignment to users.
1717
*
18-
* Each user can have multiple roles and each role can manage multiple resources. Each resource can posses a set of
19-
* permissions (CREATE, DELETE) that are only valid for that specific resource.
18+
* Each user can have multiple roles and each role can manage multiple resources. Each resource can posses a set of
19+
* permissions (CREATE, DELETE) that are only valid for that specific resource.
2020
*
21-
* The RBAC model supports antipermissions as well. One can grant antipermissions to users to restrict their access level.
22-
* There also is a special wildcard symbol "*" that means "everything". This symbol can be applied either to the
23-
* resources or permissions.
21+
* The RBAC model supports antipermissions as well. One can grant antipermissions to users to restrict their access level.
22+
* There also is a special wildcard symbol "*" that means "everything". This symbol can be applied either to the
23+
* resources or permissions.
2424
*/
2525
abstract contract RBAC is IRBAC, Initializable {
2626
using StringSet for StringSet.Set;
@@ -55,16 +55,16 @@ abstract contract RBAC is IRBAC, Initializable {
5555
}
5656

5757
/**
58-
* @notice The init function
58+
* @notice The init function
5959
*/
6060
function __RBAC_init() internal onlyInitializing {
6161
_addPermissionsToRole(MASTER_ROLE, ALL_RESOURCE, ALL_PERMISSION.asSingletonArray(), true);
6262
}
6363

6464
/**
65-
* @notice The function to grant roles to a user
66-
* @param to_ the user to grant roles to
67-
* @param rolesToGrant_ roles to grant
65+
* @notice The function to grant roles to a user
66+
* @param to_ the user to grant roles to
67+
* @param rolesToGrant_ roles to grant
6868
*/
6969
function grantRoles(
7070
address to_,
@@ -76,9 +76,9 @@ abstract contract RBAC is IRBAC, Initializable {
7676
}
7777

7878
/**
79-
* @notice The function to revoke roles
80-
* @param from_ the user to revoke roles from
81-
* @param rolesToRevoke_ the roles to revoke
79+
* @notice The function to revoke roles
80+
* @param from_ the user to revoke roles from
81+
* @param rolesToRevoke_ the roles to revoke
8282
*/
8383
function revokeRoles(
8484
address from_,
@@ -90,10 +90,10 @@ abstract contract RBAC is IRBAC, Initializable {
9090
}
9191

9292
/**
93-
* @notice The function to add resource permission to role
94-
* @param role_ the role to add permissions to
95-
* @param permissionsToAdd_ the array of resources and permissions to add to the role
96-
* @param allowed_ indicates whether to add permissions to an allowlist or disallowlist
93+
* @notice The function to add resource permission to role
94+
* @param role_ the role to add permissions to
95+
* @param permissionsToAdd_ the array of resources and permissions to add to the role
96+
* @param allowed_ indicates whether to add permissions to an allowlist or disallowlist
9797
*/
9898
function addPermissionsToRole(
9999
string memory role_,
@@ -111,10 +111,10 @@ abstract contract RBAC is IRBAC, Initializable {
111111
}
112112

113113
/**
114-
* @notice The function to remove permissions from role
115-
* @param role_ the role to remove permissions from
116-
* @param permissionsToRemove_ the array of resources and permissions to remove from the role
117-
* @param allowed_ indicates whether to remove permissions from the allowlist or disallowlist
114+
* @notice The function to remove permissions from role
115+
* @param role_ the role to remove permissions from
116+
* @param permissionsToRemove_ the array of resources and permissions to remove from the role
117+
* @param allowed_ indicates whether to remove permissions from the allowlist or disallowlist
118118
*/
119119
function removePermissionsFromRole(
120120
string memory role_,
@@ -132,19 +132,19 @@ abstract contract RBAC is IRBAC, Initializable {
132132
}
133133

134134
/**
135-
* @notice The function to get the list of user roles
136-
* @param who_ the user
137-
* @return roles_ the roles of the user
135+
* @notice The function to get the list of user roles
136+
* @param who_ the user
137+
* @return roles_ the roles of the user
138138
*/
139139
function getUserRoles(address who_) public view override returns (string[] memory roles_) {
140140
return _userRoles[who_].values();
141141
}
142142

143143
/**
144-
* @notice The function to get the permissions of the role
145-
* @param role_ the role
146-
* @return allowed_ the list of allowed permissions of the role
147-
* @return disallowed_ the list of disallowed permissions of the role
144+
* @notice The function to get the permissions of the role
145+
* @param role_ the role
146+
* @return allowed_ the list of allowed permissions of the role
147+
* @return disallowed_ the list of disallowed permissions of the role
148148
*/
149149
function getRolePermissions(
150150
string memory role_
@@ -182,13 +182,13 @@ abstract contract RBAC is IRBAC, Initializable {
182182
}
183183

184184
/**
185-
* @dev DO NOT call `super.hasPermission(...)` in derived contracts, because this method
186-
* handles not 2 but 3 states: NO PERMISSION, ALLOWED, DISALLOWED
187-
* @notice The function to check the user's possession of the role
188-
* @param who_ the user
189-
* @param resource_ the resource the user has to have the permission of
190-
* @param permission_ the permission the user has to have
191-
* @return isAllowed_ true if the user has the permission, false otherwise
185+
* @dev DO NOT call `super.hasPermission(...)` in derived contracts, because this method
186+
* handles not 2 but 3 states: NO PERMISSION, ALLOWED, DISALLOWED
187+
* @notice The function to check the user's possession of the role
188+
* @param who_ the user
189+
* @param resource_ the resource the user has to have the permission of
190+
* @param permission_ the permission the user has to have
191+
* @return isAllowed_ true if the user has the permission, false otherwise
192192
*/
193193
function hasPermission(
194194
address who_,
@@ -209,9 +209,9 @@ abstract contract RBAC is IRBAC, Initializable {
209209
}
210210

211211
/**
212-
* @notice The internal function to grant roles
213-
* @param to_ the user to grant roles to
214-
* @param rolesToGrant_ the roles to grant
212+
* @notice The internal function to grant roles
213+
* @param to_ the user to grant roles to
214+
* @param rolesToGrant_ the roles to grant
215215
*/
216216
function _grantRoles(address to_, string[] memory rolesToGrant_) internal {
217217
_userRoles[to_].add(rolesToGrant_);
@@ -220,9 +220,9 @@ abstract contract RBAC is IRBAC, Initializable {
220220
}
221221

222222
/**
223-
* @notice The internal function to revoke roles
224-
* @param from_ the user to revoke roles from
225-
* @param rolesToRevoke_ the roles to revoke
223+
* @notice The internal function to revoke roles
224+
* @param from_ the user to revoke roles from
225+
* @param rolesToRevoke_ the roles to revoke
226226
*/
227227
function _revokeRoles(address from_, string[] memory rolesToRevoke_) internal {
228228
_userRoles[from_].remove(rolesToRevoke_);
@@ -231,11 +231,11 @@ abstract contract RBAC is IRBAC, Initializable {
231231
}
232232

233233
/**
234-
* @notice The internal function to add permission to the role
235-
* @param role_ the role to add permissions to
236-
* @param resourceToAdd_ the resource to which the permissions belong
237-
* @param permissionsToAdd_ the permissions of the resource
238-
* @param allowed_ whether to add permissions to the allowlist or the disallowlist
234+
* @notice The internal function to add permission to the role
235+
* @param role_ the role to add permissions to
236+
* @param resourceToAdd_ the resource to which the permissions belong
237+
* @param permissionsToAdd_ the permissions of the resource
238+
* @param allowed_ whether to add permissions to the allowlist or the disallowlist
239239
*/
240240
function _addPermissionsToRole(
241241
string memory role_,
@@ -253,11 +253,11 @@ abstract contract RBAC is IRBAC, Initializable {
253253
}
254254

255255
/**
256-
* @notice The internal function to remove permissions from the role
257-
* @param role_ the role to remove permissions from
258-
* @param resourceToRemove_ the resource to which the permissions belong
259-
* @param permissionsToRemove_ the permissions of the resource
260-
* @param allowed_ whether to remove permissions from the allowlist or the disallowlist
256+
* @notice The internal function to remove permissions from the role
257+
* @param role_ the role to remove permissions from
258+
* @param resourceToRemove_ the resource to which the permissions belong
259+
* @param permissionsToRemove_ the permissions of the resource
260+
* @param allowed_ whether to remove permissions from the allowlist or the disallowlist
261261
*/
262262
function _removePermissionsFromRole(
263263
string memory role_,
@@ -278,11 +278,11 @@ abstract contract RBAC is IRBAC, Initializable {
278278
}
279279

280280
/**
281-
* @notice The function to check if the role has the permission
282-
* @param role_ the role to search the permission in
283-
* @param resource_ the role resource to search the permission in
284-
* @param permission_ the permission to search
285-
* @return true_ if the role has the permission, false otherwise
281+
* @notice The function to check if the role has the permission
282+
* @param role_ the role to search the permission in
283+
* @param resource_ the role resource to search the permission in
284+
* @param permission_ the permission to search
285+
* @return true_ if the role has the permission, false otherwise
286286
*/
287287
function _isAllowed(
288288
string memory role_,
@@ -301,11 +301,11 @@ abstract contract RBAC is IRBAC, Initializable {
301301
}
302302

303303
/**
304-
* @notice The function to check if the role has the antipermission
305-
* @param role_ the role to search the antipermission in
306-
* @param resource_ the role resource to search the antipermission in
307-
* @param permission_ the antipermission to search
308-
* @return true_ if the role has the antipermission, false otherwise
304+
* @notice The function to check if the role has the antipermission
305+
* @param role_ the role to search the antipermission in
306+
* @param resource_ the role resource to search the antipermission in
307+
* @param permission_ the antipermission to search
308+
* @return true_ if the role has the antipermission, false otherwise
309309
*/
310310
function _isDisallowed(
311311
string memory role_,

0 commit comments

Comments
 (0)