Skip to content

Commit

Permalink
upgrade openzepplin contracts version and match our contracts to the …
Browse files Browse the repository at this point in the history
…latest versions
  • Loading branch information
moshmage committed Aug 2, 2024
1 parent f1b90bc commit 150b803
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 298 deletions.
2 changes: 1 addition & 1 deletion contracts/access/Governed.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity >=0.6.0;
pragma solidity >=0.8.0;


/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/access/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity >=0.6.0;
pragma solidity >=0.8.0;

/**
* @title Ownable
Expand Down
2 changes: 1 addition & 1 deletion contracts/access/ReentrancyGuardOptimized.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.8.0;

/**
* @dev Contract module that helps prevent reentrant calls to a function.
Expand Down
2 changes: 1 addition & 1 deletion contracts/bepro/INetworkV2.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity >=0.6.0;
pragma solidity >=0.8.0;
pragma abicoder v2;

import "./token/ERC721/BountyToken.sol";
Expand Down
31 changes: 20 additions & 11 deletions contracts/bepro/NetworkRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity >=0.6.0 <=8.0.0;
pragma solidity >=0.8.0;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import "./INetworkV2.sol";
Expand All @@ -18,7 +18,7 @@ import "./token/ERC721/BountyToken.sol";
*/
contract NetworkRegistry is ReentrancyGuard, Governed {

using SafeMath for uint256;
using Math for uint256;
using EnumerableSet for EnumerableSet.AddressSet;

uint256 constant MAX_PERCENT = 100000000;
Expand Down Expand Up @@ -100,8 +100,8 @@ contract NetworkRegistry is ReentrancyGuard, Governed {
require(_amount > 0, "L0");
require(erc20.transferFrom(msg.sender, address(this), _amount), "L1");

lockedTokensOfAddress[msg.sender] = lockedTokensOfAddress[msg.sender].add(_amount);
totalLockedAmount = totalLockedAmount.add(_amount);
lockedTokensOfAddress[msg.sender] = lockedTokensOfAddress[msg.sender] + _amount;
totalLockedAmount = totalLockedAmount + _amount;

emit UserLockedAmountChanged(msg.sender, lockedTokensOfAddress[msg.sender]);
}
Expand Down Expand Up @@ -132,7 +132,9 @@ contract NetworkRegistry is ReentrancyGuard, Governed {

require(erc20.transfer(msg.sender, lockedTokensOfAddress[msg.sender]), "UL3");

totalLockedAmount = totalLockedAmount.sub(lockedTokensOfAddress[msg.sender]);
(, uint256 newTotalLockedAmount) = totalLockedAmount.trySub(lockedTokensOfAddress[msg.sender]);

totalLockedAmount = newTotalLockedAmount;
lockedTokensOfAddress[msg.sender] = 0;

emit UserLockedAmountChanged(msg.sender, lockedTokensOfAddress[msg.sender]);
Expand All @@ -152,22 +154,28 @@ contract NetworkRegistry is ReentrancyGuard, Governed {
*/
function registerNetwork(address networkAddress) nonReentrant external {
INetworkV2 network = INetworkV2(networkAddress);
uint256 fee = (lockAmountForNetworkCreation.mul(networkCreationFeePercentage)).div(MAX_PERCENT);
uint256 fee = lockAmountForNetworkCreation.mulDiv(networkCreationFeePercentage, MAX_PERCENT);

require(networkOfAddress[msg.sender] == address(0), "R0");
require(lockedTokensOfAddress[msg.sender] >= lockAmountForNetworkCreation, "R1");
require(network._governor() == msg.sender, "R2");
require(address(network.registry()) == address(this), "R4");

if (treasury != address(0)) {
(, uint256 newTotalLockedAmount) = totalLockedAmount.trySub(fee);
totalLockedAmount = newTotalLockedAmount;

require(erc20.transfer(treasury, fee), "R3");
totalLockedAmount = totalLockedAmount.sub(fee);
}

networksArray.push(network);
openNetworks[networkAddress] = true;
networkOfAddress[msg.sender] = networkAddress;
lockedTokensOfAddress[msg.sender] = lockedTokensOfAddress[msg.sender].sub(fee);

(, uint256 newUserLockedAmount) = lockedTokensOfAddress[msg.sender].trySub(fee);

lockedTokensOfAddress[msg.sender] = newUserLockedAmount;

emit NetworkRegistered(networkAddress, msg.sender, networksArray.length - 1);
}

Expand Down Expand Up @@ -202,7 +210,8 @@ contract NetworkRegistry is ReentrancyGuard, Governed {
EnumerableSet.AddressSet storage pointer = transactional ? _transactionalTokens : _rewardTokens;
uint256 len = _erc20Addresses.length;

require(len.add(pointer.length()) <= MAX_ALLOWED_TOKENS_LEN, "AT0");
(, uint256 tokensLength) = len.tryAdd(pointer.length());
require(tokensLength <= MAX_ALLOWED_TOKENS_LEN, "AT0");

for (uint256 z = 0; z < len; z++) {
require(pointer.add(_erc20Addresses[z]) == true, "AT1");
Expand Down
Loading

0 comments on commit 150b803

Please sign in to comment.