Skip to content

Commit 1e8cf86

Browse files
committed
paginator & EIP-6224 fix
1 parent 07d1bc4 commit 1e8cf86

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

contracts/contracts-registry/AbstractContractsRegistry.sol

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ abstract contract AbstractContractsRegistry is Initializable {
4141
mapping(string => address) private _contracts;
4242
mapping(address => bool) private _isProxy;
4343

44-
event AddedContract(string name, address contractAddress, bool isProxy);
45-
event RemovedContract(string name);
44+
event ContractAdded(string name, address contractAddress);
45+
event ProxyContractAdded(string name, address contractAddress, address implementation);
46+
event ProxyContractUpgraded(string name, address newImplementation);
47+
event ContractRemoved(string name);
4648

4749
/**
4850
* @notice The proxy initializer function
@@ -147,6 +149,8 @@ abstract contract AbstractContractsRegistry is Initializable {
147149
require(_isProxy[contractToUpgrade_], "ContractsRegistry: not a proxy contract");
148150

149151
_proxyUpgrader.upgrade(contractToUpgrade_, newImplementation_, data_);
152+
153+
emit ProxyContractUpgraded(name_, newImplementation_);
150154
}
151155

152156
/**
@@ -160,7 +164,7 @@ abstract contract AbstractContractsRegistry is Initializable {
160164

161165
_contracts[name_] = contractAddress_;
162166

163-
emit AddedContract(name_, contractAddress_, false);
167+
emit ContractAdded(name_, contractAddress_);
164168
}
165169

166170
/**
@@ -179,7 +183,7 @@ abstract contract AbstractContractsRegistry is Initializable {
179183
_contracts[name_] = proxyAddr_;
180184
_isProxy[proxyAddr_] = true;
181185

182-
emit AddedContract(name_, proxyAddr_, true);
186+
emit ProxyContractAdded(name_, proxyAddr_, contractAddress_);
183187
}
184188

185189
/**
@@ -195,7 +199,11 @@ abstract contract AbstractContractsRegistry is Initializable {
195199
_contracts[name_] = contractAddress_;
196200
_isProxy[contractAddress_] = true;
197201

198-
emit AddedContract(name_, contractAddress_, true);
202+
emit ProxyContractAdded(
203+
name_,
204+
contractAddress_,
205+
_proxyUpgrader.getImplementation(contractAddress_)
206+
);
199207
}
200208

201209
/**
@@ -210,6 +218,6 @@ abstract contract AbstractContractsRegistry is Initializable {
210218
delete _isProxy[contractAddress_];
211219
delete _contracts[name_];
212220

213-
emit RemovedContract(name_);
221+
emit ContractRemoved(name_);
214222
}
215223
}

contracts/contracts-registry/proxy/ProxyUpgrader.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ contract ProxyUpgrader {
1515

1616
address private immutable _OWNER;
1717

18-
event Upgraded(address proxy, address implementation);
19-
2018
modifier onlyOwner() {
21-
require(_OWNER == msg.sender, "ProxyUpgrader: not an owner");
19+
_onlyOwner();
2220
_;
2321
}
2422

@@ -32,15 +30,18 @@ contract ProxyUpgrader {
3230
} else {
3331
TransparentUpgradeableProxy(payable(what_)).upgradeTo(to_);
3432
}
35-
36-
emit Upgraded(what_, to_);
3733
}
3834

3935
function getImplementation(address what_) external view onlyOwner returns (address) {
4036
// bytes4(keccak256("implementation()")) == 0x5c60da1b
4137
(bool success_, bytes memory returndata_) = address(what_).staticcall(hex"5c60da1b");
42-
require(success_);
38+
39+
require(success_, "ProxyUpgrader: not a proxy");
4340

4441
return abi.decode(returndata_, (address));
4542
}
43+
44+
function _onlyOwner() internal view {
45+
require(_OWNER == msg.sender, "ProxyUpgrader: not an owner");
46+
}
4647
}

contracts/libs/arrays/Paginator.sol

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {StringSet} from "../data-structures/StringSet.sol";
1010
*
1111
* Supports the following data types `uin256[]`, `address[]`, `bytes32[]`, `UintSet`,
1212
* `AddressSet`, `BytesSet`, `StringSet`.
13-
*
1413
*/
1514
library Paginator {
1615
using EnumerableSet for *;
@@ -34,7 +33,7 @@ library Paginator {
3433
uint256 offset_,
3534
uint256 limit_
3635
) internal view returns (uint256[] memory list_) {
37-
uint256 to_ = _handleIncomingParametersForPart(arr.length, offset_, limit_);
36+
uint256 to_ = getTo(arr.length, offset_, limit_);
3837

3938
list_ = new uint256[](to_ - offset_);
4039

@@ -48,7 +47,7 @@ library Paginator {
4847
uint256 offset_,
4948
uint256 limit_
5049
) internal view returns (address[] memory list_) {
51-
uint256 to_ = _handleIncomingParametersForPart(arr.length, offset_, limit_);
50+
uint256 to_ = getTo(arr.length, offset_, limit_);
5251

5352
list_ = new address[](to_ - offset_);
5453

@@ -62,7 +61,7 @@ library Paginator {
6261
uint256 offset_,
6362
uint256 limit_
6463
) internal view returns (bytes32[] memory list_) {
65-
uint256 to_ = _handleIncomingParametersForPart(arr.length, offset_, limit_);
64+
uint256 to_ = getTo(arr.length, offset_, limit_);
6665

6766
list_ = new bytes32[](to_ - offset_);
6867

@@ -76,7 +75,7 @@ library Paginator {
7675
uint256 offset_,
7776
uint256 limit_
7877
) internal view returns (uint256[] memory list_) {
79-
uint256 to_ = _handleIncomingParametersForPart(set.length(), offset_, limit_);
78+
uint256 to_ = getTo(set.length(), offset_, limit_);
8079

8180
list_ = new uint256[](to_ - offset_);
8281

@@ -90,7 +89,7 @@ library Paginator {
9089
uint256 offset_,
9190
uint256 limit_
9291
) internal view returns (address[] memory list_) {
93-
uint256 to_ = _handleIncomingParametersForPart(set.length(), offset_, limit_);
92+
uint256 to_ = getTo(set.length(), offset_, limit_);
9493

9594
list_ = new address[](to_ - offset_);
9695

@@ -104,7 +103,7 @@ library Paginator {
104103
uint256 offset_,
105104
uint256 limit_
106105
) internal view returns (bytes32[] memory list_) {
107-
uint256 to_ = _handleIncomingParametersForPart(set.length(), offset_, limit_);
106+
uint256 to_ = getTo(set.length(), offset_, limit_);
108107

109108
list_ = new bytes32[](to_ - offset_);
110109

@@ -118,7 +117,7 @@ library Paginator {
118117
uint256 offset_,
119118
uint256 limit_
120119
) internal view returns (string[] memory list_) {
121-
uint256 to_ = _handleIncomingParametersForPart(set.length(), offset_, limit_);
120+
uint256 to_ = getTo(set.length(), offset_, limit_);
122121

123122
list_ = new string[](to_ - offset_);
124123

@@ -127,11 +126,11 @@ library Paginator {
127126
}
128127
}
129128

130-
function _handleIncomingParametersForPart(
129+
function getTo(
131130
uint256 length_,
132131
uint256 offset_,
133132
uint256 limit_
134-
) private pure returns (uint256 to_) {
133+
) internal pure returns (uint256 to_) {
135134
to_ = offset_ + limit_;
136135

137136
if (to_ > length_) {

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dlsl/dev-modules",
3-
"version": "2.3.4",
3+
"version": "2.4.0",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"readme": "README.md",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dlsl",
3-
"version": "2.3.4",
3+
"version": "2.4.0",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"description": "Solidity Development Modules by Distributed Lab",

test/contracts-registry/ProxyUpgrader.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("ProxyUpgrader", () => {
4444
});
4545

4646
it("should not get implementation", async () => {
47-
await truffleAssert.reverts(proxyUpgrader.getImplementation(token.address));
47+
await truffleAssert.reverts(proxyUpgrader.getImplementation(token.address), "ProxyUpgrader: not a proxy");
4848
});
4949

5050
it("only owner should get implementation", async () => {

0 commit comments

Comments
 (0)