Skip to content

Commit 7de2d04

Browse files
authored
Bump solidity-lib version (#9)
* Bumped solidity-lib version * Minor refactoring. Fixed tests
1 parent b8fee31 commit 7de2d04

File tree

8 files changed

+79
-110
lines changed

8 files changed

+79
-110
lines changed

contracts/core/KYCCompliance.sol

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ pragma solidity ^0.8.21;
33

44
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
55

6-
import {SetHelper} from "@solarity/solidity-lib/libs/arrays/SetHelper.sol";
7-
86
import {IKYCCompliance} from "../interfaces/core/IKYCCompliance.sol";
97

108
import {IAssetF} from "../interfaces/IAssetF.sol";
@@ -22,7 +20,9 @@ import {AbstractKYCModule} from "../modules/AbstractKYCModule.sol";
2220
*/
2321
abstract contract KYCCompliance is IKYCCompliance, KYCComplianceStorage, AgentAccessControl {
2422
using EnumerableSet for EnumerableSet.AddressSet;
25-
using SetHelper for EnumerableSet.AddressSet;
23+
24+
error FailedToAddKYCModule(address kycModule);
25+
error FailedToRemoveKYCModule(address kycModule);
2626

2727
function __KYCCompliance_init() internal onlyInitializing {}
2828

@@ -54,11 +54,23 @@ abstract contract KYCCompliance is IKYCCompliance, KYCComplianceStorage, AgentAc
5454
}
5555

5656
function _addKYCModules(address[] memory kycModules_) internal virtual {
57-
_getKYCComplianceStorage().kycModules.strictAdd(kycModules_);
57+
KYCCStorage storage $ = _getKYCComplianceStorage();
58+
59+
uint256 length_ = kycModules_.length;
60+
for (uint256 i = 0; i < length_; ++i) {
61+
address kycModule_ = kycModules_[i];
62+
require($.kycModules.add(kycModule_), FailedToAddKYCModule(kycModule_));
63+
}
5864
}
5965

6066
function _removeKYCModules(address[] memory kycModules_) internal virtual {
61-
_getKYCComplianceStorage().kycModules.strictRemove(kycModules_);
67+
KYCCStorage storage $ = _getKYCComplianceStorage();
68+
69+
uint256 length_ = kycModules_.length;
70+
for (uint256 i = 0; i < length_; ++i) {
71+
address kycModule_ = kycModules_[i];
72+
require($.kycModules.remove(kycModule_), FailedToRemoveKYCModule(kycModule_));
73+
}
6274
}
6375

6476
function _KYCComplianceRole() internal view virtual returns (bytes32) {

contracts/core/RegulatoryCompliance.sol

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ pragma solidity ^0.8.21;
33

44
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
55

6-
import {SetHelper} from "@solarity/solidity-lib/libs/arrays/SetHelper.sol";
7-
86
import {IRegulatoryCompliance} from "../interfaces/core/IRegulatoryCompliance.sol";
97

108
import {IAssetF} from "../interfaces/IAssetF.sol";
@@ -26,7 +24,9 @@ abstract contract RegulatoryCompliance is
2624
AgentAccessControl
2725
{
2826
using EnumerableSet for EnumerableSet.AddressSet;
29-
using SetHelper for EnumerableSet.AddressSet;
27+
28+
error FailedToAddRegulatoryModule(address regulatoryModule);
29+
error FailedToRemoveRegulatoryModule(address regulatoryModule);
3030

3131
modifier onlyThisContract() {
3232
require(msg.sender == address(this), SenderIsNotThisContract(msg.sender));
@@ -72,11 +72,29 @@ abstract contract RegulatoryCompliance is
7272
}
7373

7474
function _addRegulatoryModules(address[] memory regulatoryModules_) internal virtual {
75-
_getRegulatoryComplianceStorage().regulatoryModules.strictAdd(regulatoryModules_);
75+
RCStorage storage $ = _getRegulatoryComplianceStorage();
76+
77+
uint256 length_ = regulatoryModules_.length;
78+
for (uint256 i = 0; i < length_; ++i) {
79+
address regulatoryModule_ = regulatoryModules_[i];
80+
require(
81+
$.regulatoryModules.add(regulatoryModule_),
82+
FailedToAddRegulatoryModule(regulatoryModule_)
83+
);
84+
}
7685
}
7786

7887
function _removeRegulatoryModules(address[] memory regulatoryModules_) internal virtual {
79-
_getRegulatoryComplianceStorage().regulatoryModules.strictRemove(regulatoryModules_);
88+
RCStorage storage $ = _getRegulatoryComplianceStorage();
89+
90+
uint256 length_ = regulatoryModules_.length;
91+
for (uint256 i = 0; i < length_; ++i) {
92+
address regulatoryModule_ = regulatoryModules_[i];
93+
require(
94+
$.regulatoryModules.remove(regulatoryModule_),
95+
FailedToRemoveRegulatoryModule(regulatoryModule_)
96+
);
97+
}
8098
}
8199

82100
function _regulatoryComplianceRole() internal view virtual returns (bytes32) {

contracts/modules/AbstractModule.sol

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ pragma solidity ^0.8.21;
44
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
55
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
66

7-
import {SetHelper} from "@solarity/solidity-lib/libs/arrays/SetHelper.sol";
8-
97
import {IAgentAccessControl} from "../interfaces/core/IAgentAccessControl.sol";
108

119
import {IAssetF} from "../interfaces/IAssetF.sol";
@@ -20,7 +18,6 @@ import {IAssetF} from "../interfaces/IAssetF.sol";
2018
*/
2119
abstract contract AbstractModule is Initializable {
2220
using EnumerableSet for EnumerableSet.Bytes32Set;
23-
using SetHelper for EnumerableSet.Bytes32Set;
2421

2522
// keccak256("tokenf.standard.abstract.module.storage")
2623
bytes32 private constant ABSTRACT_MODULE_STORAGE =
@@ -43,6 +40,8 @@ abstract contract AbstractModule is Initializable {
4340
}
4441

4542
error HandlerNotSet();
43+
error FailedToAddHandlerTopic(bytes32 handlerTopic);
44+
error FailedToRemoveHandlerTopic(bytes32 handlerTopic);
4645

4746
function __AbstractModule_init(address assetF_) internal onlyInitializing {
4847
AbstractModuleStorage storage $ = _getAbstractModuleStorage();
@@ -140,7 +139,14 @@ abstract contract AbstractModule is Initializable {
140139
) internal virtual {
141140
AbstractModuleStorage storage $ = _getAbstractModuleStorage();
142141

143-
$.handlerTopics[contextKey_].strictAdd(handlerTopics_);
142+
uint256 length_ = handlerTopics_.length;
143+
for (uint256 i = 0; i < length_; ++i) {
144+
bytes32 handlerTopic_ = handlerTopics_[i];
145+
require(
146+
$.handlerTopics[contextKey_].add(handlerTopic_),
147+
FailedToAddHandlerTopic(handlerTopic_)
148+
);
149+
}
144150
}
145151

146152
/**
@@ -158,7 +164,14 @@ abstract contract AbstractModule is Initializable {
158164
) internal virtual {
159165
AbstractModuleStorage storage $ = _getAbstractModuleStorage();
160166

161-
$.handlerTopics[contextKey_].strictRemove(handlerTopics_);
167+
uint256 length_ = handlerTopics_.length;
168+
for (uint256 i = 0; i < length_; ++i) {
169+
bytes32 handlerTopic_ = handlerTopics_[i];
170+
require(
171+
$.handlerTopics[contextKey_].remove(handlerTopic_),
172+
FailedToRemoveHandlerTopic(handlerTopic_)
173+
);
174+
}
162175
}
163176

164177
/**

package-lock.json

Lines changed: 13 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tokenf/contracts",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"description": "On-chain Real World Assets Tokenization Framework",
@@ -40,7 +40,7 @@
4040
"dependencies": {
4141
"@openzeppelin/contracts": "5.3.0",
4242
"@openzeppelin/contracts-upgradeable": "5.3.0",
43-
"@solarity/solidity-lib": "3.1.4"
43+
"@solarity/solidity-lib": "3.2.8"
4444
},
4545
"devDependencies": {
4646
"@metamask/eth-sig-util": "^8.2.0",

test/core/KYCCompliance.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe("KYCCompliance", () => {
9090

9191
it("should not add KYC modules if duplicates", async () => {
9292
await expect(kycComplianceProxy.connect(agent).addKYCModules([kycCorrect, kycCorrect]))
93-
.to.be.revertedWithCustomError(kycComplianceProxy, "ElementAlreadyExistsAddress")
93+
.to.be.revertedWithCustomError(kycComplianceProxy, "FailedToAddKYCModule")
9494
.withArgs(kycCorrect);
9595
});
9696

@@ -113,7 +113,7 @@ describe("KYCCompliance", () => {
113113

114114
it("should not remove KYC modules if no module", async () => {
115115
await expect(kycComplianceProxy.connect(agent).removeKYCModules([kycCorrect]))
116-
.to.be.revertedWithCustomError(kycComplianceProxy, "NoSuchAddress")
116+
.to.be.revertedWithCustomError(kycComplianceProxy, "FailedToRemoveKYCModule")
117117
.withArgs(kycCorrect);
118118
});
119119

test/core/RegulatoryCompliance.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe("RegulatoryCompliance", () => {
100100

101101
it("should not add regulatory modules if duplicates", async () => {
102102
await expect(rComplianceProxy.connect(agent).addRegulatoryModules([rCorrect, rCorrect]))
103-
.to.be.revertedWithCustomError(rComplianceProxy, "ElementAlreadyExistsAddress")
103+
.to.be.revertedWithCustomError(rComplianceProxy, "FailedToAddRegulatoryModule")
104104
.withArgs(rCorrect);
105105
});
106106

@@ -123,7 +123,7 @@ describe("RegulatoryCompliance", () => {
123123

124124
it("should not remove regulatory modules if no module", async () => {
125125
await expect(rComplianceProxy.connect(agent).removeRegulatoryModules([rCorrect]))
126-
.to.be.revertedWithCustomError(rComplianceProxy, "NoSuchAddress")
126+
.to.be.revertedWithCustomError(rComplianceProxy, "FailedToRemoveRegulatoryModule")
127127
.withArgs(rCorrect);
128128
});
129129

test/modules/AbstractModules.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe("AbstractModules", () => {
126126

127127
it("should not add handler topics if duplicates", async () => {
128128
await expect(module.connect(agent).addHandlerTopics(ZERO_BYTES32, [ZERO_BYTES32, ZERO_BYTES32]))
129-
.to.be.revertedWithCustomError(module, "ElementAlreadyExistsBytes32")
129+
.to.be.revertedWithCustomError(module, "FailedToAddHandlerTopic")
130130
.withArgs(ZERO_BYTES32);
131131
});
132132

@@ -148,7 +148,7 @@ describe("AbstractModules", () => {
148148

149149
it("should not remove handler topics if no handler topic", async () => {
150150
await expect(module.connect(agent).removeHandlerTopics(ZERO_BYTES32, [ZERO_BYTES32]))
151-
.to.be.revertedWithCustomError(module, "NoSuchBytes32")
151+
.to.be.revertedWithCustomError(module, "FailedToRemoveHandlerTopic")
152152
.withArgs(ZERO_BYTES32);
153153
});
154154

0 commit comments

Comments
 (0)