Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update some contracts to use solidity 0.8 #725

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
},
skipFiles,
istanbulFolder: './reports/coverage',
configureYulOptimizer: true,
}
14 changes: 9 additions & 5 deletions contracts/arbitrum/AddressAliasHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/84e64dee6ee82adbf8ec34fd4b86c207a61d9007/packages/arb-bridge-eth
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
*
* - Changed solidity version to >=0.8.0 <0.9.0 ([email protected])
* - Added an unchecked to the alias calculation to work on 0.8
*/

pragma solidity ^0.7.6;
pragma solidity >=0.8.0 <0.9.0;

library AddressAliasHelper {
uint160 constant offset = uint160(0x1111000000000000000000000000000000001111);
Expand All @@ -33,14 +33,18 @@ library AddressAliasHelper {
/// @param l1Address the address in the L1 that triggered the tx to L2
/// @return l2Address L2 address as viewed in msg.sender
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
l2Address = address(uint160(l1Address) + offset);
unchecked {
l2Address = address(uint160(l1Address) + offset);
}
}

/// @notice Utility function that converts the msg.sender viewed in the L2 to the
/// address in the L1 that submitted a tx to the inbox
/// @param l2Address L2 address as viewed in msg.sender
/// @return l1Address the address in the L1 that triggered the tx to L2
function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {
l1Address = address(uint160(l2Address) - offset);
unchecked {
l1Address = address(uint160(l2Address) - offset);
}
}
}
4 changes: 2 additions & 2 deletions contracts/arbitrum/IArbToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-peripherals
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

/**
* @title Minimum expected interface for L2 token that interacts with the L2 token bridge (this is the interface necessary
* for a custom token that interacts with the bridge, see TestArbCustomToken.sol for an example implementation).
*/
pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

interface IArbToken {
/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-eth
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

interface IBridge {
event MessageDelivered(
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/IInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-eth
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

import "./IBridge.sol";
import "./IMessageProvider.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/IMessageProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-eth
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

interface IMessageProvider {
event InboxMessageDelivered(uint256 indexed messageNum, bytes data);
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/IOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-eth
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

interface IOutbox {
event OutboxEntryCreated(
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/ITokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-peripherals
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

interface ITokenGateway {
/// @notice event deprecated in favor of DepositInitiated and WithdrawalInitiated
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/L1ArbitrumMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-peripherals
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

import "./IInbox.sol";
import "./IOutbox.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/arbitrum/L2ArbitrumMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* https://github.com/OffchainLabs/arbitrum/tree/e3a6307ad8a2dc2cad35728a2a9908cfd8dd8ef9/packages/arb-bridge-peripherals
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
* - Changed solidity version to >=0.7.0 <0.9.0 ([email protected])
*
*/

pragma solidity ^0.7.6;
pragma solidity >=0.7.0 <0.9.0;

import "arbos-precompiles/arbos/builtin/ArbSys.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/arbitrum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

These contracts have been copied from the [Arbitrum repo](https://github.com/OffchainLabs/arbitrum).

They are also available as part of the npm packages [arb-bridge-eth](https://www.npmjs.com/package/arb-bridge-eth) and [arb-bridge-peripherals](https://www.npmjs.com/package/arb-bridge-peripherals). The reason for copying them rather than installing those packages is the contracts only support Solidity `^0.6.11`, so we had to change the version to `^0.7.6` for it to be compatible with our other contracts.
They are also available as part of the npm packages [arb-bridge-eth](https://www.npmjs.com/package/arb-bridge-eth) and [arb-bridge-peripherals](https://www.npmjs.com/package/arb-bridge-peripherals). The reason for copying them rather than installing those packages is the contracts only support Solidity `^0.6.11`, so we had to change the version to `>=0.7.0 <0.9.0` for it to be compatible with our other contracts.
32 changes: 14 additions & 18 deletions contracts/bancor/BancorFormula.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.7.6;

import "@openzeppelin/contracts/math/SafeMath.sol";
pragma solidity ^0.8.16;

contract BancorFormula {
using SafeMath for uint256;

uint16 public constant version = 6;

uint256 private constant ONE = 1;
Expand Down Expand Up @@ -199,13 +195,13 @@ contract BancorFormula {
if (_depositAmount == 0) return 0;

// special case if the ratio = 100%
if (_reserveRatio == MAX_RATIO) return _supply.mul(_depositAmount) / _reserveBalance;
if (_reserveRatio == MAX_RATIO) return (_supply * _depositAmount) / _reserveBalance;

uint256 result;
uint8 precision;
uint256 baseN = _depositAmount.add(_reserveBalance);
uint256 baseN = _depositAmount + _reserveBalance;
(result, precision) = power(baseN, _reserveBalance, _reserveRatio, MAX_RATIO);
uint256 temp = _supply.mul(result) >> precision;
uint256 temp = (_supply * result) >> precision;
return temp - _supply;
}

Expand Down Expand Up @@ -246,13 +242,13 @@ contract BancorFormula {
if (_sellAmount == _supply) return _reserveBalance;

// special case if the ratio = 100%
if (_reserveRatio == MAX_RATIO) return _reserveBalance.mul(_sellAmount) / _supply;
if (_reserveRatio == MAX_RATIO) return (_reserveBalance * _sellAmount) / _supply;

uint256 result;
uint8 precision;
uint256 baseD = _supply - _sellAmount;
(result, precision) = power(_supply, baseD, MAX_RATIO, _reserveRatio);
uint256 temp1 = _reserveBalance.mul(result);
uint256 temp1 = _reserveBalance * result;
uint256 temp2 = _reserveBalance << precision;
return (temp1 - temp2) / result;
}
Expand Down Expand Up @@ -292,13 +288,13 @@ contract BancorFormula {

// special case for equal ratios
if (_fromReserveRatio == _toReserveRatio)
return _toReserveBalance.mul(_amount) / _fromReserveBalance.add(_amount);
return (_toReserveBalance * _amount) / (_fromReserveBalance + _amount);

uint256 result;
uint8 precision;
uint256 baseN = _fromReserveBalance.add(_amount);
uint256 baseN = _fromReserveBalance + _amount;
(result, precision) = power(baseN, _fromReserveBalance, _fromReserveRatio, _toReserveRatio);
uint256 temp1 = _toReserveBalance.mul(result);
uint256 temp1 = _toReserveBalance * result;
uint256 temp2 = _toReserveBalance << precision;
return (temp1 - temp2) / result;
}
Expand Down Expand Up @@ -332,13 +328,13 @@ contract BancorFormula {
if (_amount == 0) return 0;

// special case if the total ratio = 100%
if (_totalRatio == MAX_RATIO) return (_amount.mul(_reserveBalance) - 1) / _supply + 1;
if (_totalRatio == MAX_RATIO) return ((_amount * _reserveBalance) - 1) / _supply + 1;

uint256 result;
uint8 precision;
uint256 baseN = _supply.add(_amount);
uint256 baseN = _supply + _amount;
(result, precision) = power(baseN, _supply, MAX_RATIO, _totalRatio);
uint256 temp = ((_reserveBalance.mul(result) - 1) >> precision) + 1;
uint256 temp = (((_reserveBalance * result) - 1) >> precision) + 1;
return temp - _reserveBalance;
}

Expand Down Expand Up @@ -378,13 +374,13 @@ contract BancorFormula {
if (_amount == _supply) return _reserveBalance;

// special case if the total ratio = 100%
if (_totalRatio == MAX_RATIO) return _amount.mul(_reserveBalance) / _supply;
if (_totalRatio == MAX_RATIO) return (_amount * _reserveBalance) / _supply;

uint256 result;
uint8 precision;
uint256 baseD = _supply - _amount;
(result, precision) = power(_supply, baseD, MAX_RATIO, _totalRatio);
uint256 temp1 = _reserveBalance.mul(result);
uint256 temp1 = _reserveBalance * result;
uint256 temp2 = _reserveBalance << precision;
return (temp1 - temp2) / result;
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/base/IMulticall.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma abicoder v2;
pragma solidity >=0.7.0 <0.9.0;

/**
* @title Multicall interface
Expand Down
5 changes: 2 additions & 3 deletions contracts/base/Multicall.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma abicoder v2;
pragma solidity ^0.8.16;

import "./IMulticall.sol";
import { IMulticall } from "./IMulticall.sol";

// Inspired by https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/base/Multicall.sol
// Note: Removed payable from the multicall
Expand Down
48 changes: 23 additions & 25 deletions contracts/curation/Curation.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol";

import "../bancor/BancorFormula.sol";
import "../upgrades/GraphUpgradeable.sol";
import "../utils/TokenUtils.sol";
import { BancorFormula } from "../bancor/BancorFormula.sol";
import { GraphUpgradeable } from "../upgrades/GraphUpgradeable.sol";
import { TokenUtils } from "../utils/TokenUtils.sol";

import "./CurationStorage.sol";
import "./ICuration.sol";
import "./GraphCurationToken.sol";
import { CurationV1Storage } from "./CurationStorage.sol";
import { ICuration } from "./ICuration.sol";
import { IGraphCurationToken } from "./IGraphCurationToken.sol";
import { IRewardsManager } from "../rewards/IRewardsManager.sol";
import { Managed } from "../governance/Managed.sol";
import { IGraphToken } from "../token/IGraphToken.sol";

/**
* @title Curation contract
Expand All @@ -27,8 +29,6 @@ import "./GraphCurationToken.sol";
* bonding curve.
*/
contract Curation is CurationV1Storage, GraphUpgradeable {
using SafeMath for uint256;

// 100% in parts per million
uint32 private constant MAX_PPM = 1000000;

Expand Down Expand Up @@ -202,7 +202,7 @@ contract Curation is CurationV1Storage, GraphUpgradeable {

// Collect new funds into reserve
CurationPool storage curationPool = pools[_subgraphDeploymentID];
curationPool.tokens = curationPool.tokens.add(_tokens);
curationPool.tokens = curationPool.tokens + _tokens;

emit Collected(_subgraphDeploymentID, _tokens);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ contract Curation is CurationV1Storage, GraphUpgradeable {
TokenUtils.burnTokens(_graphToken, curationTax);

// Update curation pool
curationPool.tokens = curationPool.tokens.add(_tokensIn.sub(curationTax));
curationPool.tokens = curationPool.tokens + (_tokensIn - curationTax);
curationPool.gcs.mint(curator, signalOut);

emit Signalled(curator, _subgraphDeploymentID, _tokensIn, signalOut, curationTax);
Expand Down Expand Up @@ -297,7 +297,7 @@ contract Curation is CurationV1Storage, GraphUpgradeable {

// Update curation pool
CurationPool storage curationPool = pools[_subgraphDeploymentID];
curationPool.tokens = curationPool.tokens.sub(tokensOut);
curationPool.tokens = curationPool.tokens - tokensOut;
curationPool.gcs.burnFrom(curator, _signalIn);

// If all signal burnt delete the curation pool except for the
Expand Down Expand Up @@ -382,8 +382,8 @@ contract Curation is CurationV1Storage, GraphUpgradeable {
override
returns (uint256, uint256)
{
uint256 curationTax = _tokensIn.mul(uint256(curationTaxPercentage)).div(MAX_PPM);
uint256 signalOut = _tokensToSignal(_subgraphDeploymentID, _tokensIn.sub(curationTax));
uint256 curationTax = (_tokensIn * uint256(curationTaxPercentage)) / MAX_PPM;
uint256 signalOut = _tokensToSignal(_subgraphDeploymentID, _tokensIn - curationTax);
return (signalOut, curationTax);
}

Expand All @@ -408,14 +408,12 @@ contract Curation is CurationV1Storage, GraphUpgradeable {
"Curation deposit is below minimum required"
);
return
BancorFormula(bondingCurve)
.calculatePurchaseReturn(
SIGNAL_PER_MINIMUM_DEPOSIT,
minimumCurationDeposit,
defaultReserveRatio,
_tokensIn.sub(minimumCurationDeposit)
)
.add(SIGNAL_PER_MINIMUM_DEPOSIT);
BancorFormula(bondingCurve).calculatePurchaseReturn(
SIGNAL_PER_MINIMUM_DEPOSIT,
minimumCurationDeposit,
defaultReserveRatio,
_tokensIn - minimumCurationDeposit
) + SIGNAL_PER_MINIMUM_DEPOSIT;
}

return
Expand Down
6 changes: 4 additions & 2 deletions contracts/curation/CurationStorage.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.7.6;
pragma solidity ^0.8.16;

import "../governance/Managed.sol";
import { Managed } from "../governance/Managed.sol";
import { ICuration } from "./ICuration.sol";
import { IGraphCurationToken } from "./IGraphCurationToken.sol";

abstract contract CurationV1Storage is Managed, ICuration {
// -- Pool --
Expand Down
Loading