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

[SC-989][SC-990] Solidity 0.8.23, OZ 5.0.0 #140

Merged
merged 11 commits into from
Dec 21, 2023
Merged
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
25 changes: 0 additions & 25 deletions .github/actions/setup/action.yml

This file was deleted.

20 changes: 15 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,32 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'
- run: yarn
- run: yarn lint

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'
- run: yarn
- run: yarn test:ci

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'
- run: yarn
- run: yarn coverage
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "0.8.19"
"solidity.compileUsingRemoteVersion": "0.8.23"
}
31 changes: 15 additions & 16 deletions contracts/FeeBank.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@1inch/solidity-utils/contracts/libraries/SafeERC20.sol";
Expand All @@ -19,23 +19,22 @@ contract FeeBank is IFeeBank, Ownable {

error ZeroAddress();

IERC20 private immutable _token;
IFeeBankCharger private immutable _charger;
IERC20 private immutable _TOKEN;
IFeeBankCharger private immutable _CHARGER;

mapping(address account => uint256 availableCredit) private _accountDeposits;

constructor(IFeeBankCharger charger_, IERC20 inch_, address owner_) {
constructor(IFeeBankCharger charger_, IERC20 inch_, address owner_) Ownable(owner_) {
if (address(inch_) == address(0)) revert ZeroAddress();
_charger = charger_;
_token = inch_;
transferOwnership(owner_);
_CHARGER = charger_;
_TOKEN = inch_;
}

/**
* @notice See {IFeeBank-availableCredit}.
*/
function availableCredit(address account) external view returns (uint256) {
return _charger.availableCredit(account);
return _CHARGER.availableCredit(account);
}

/**
Expand Down Expand Up @@ -67,7 +66,7 @@ contract FeeBank is IFeeBank, Ownable {
uint256 amount,
bytes calldata permit
) public returns (uint256) {
_token.safePermit(permit);
_TOKEN.safePermit(permit);
return _depositFor(account, amount);
}

Expand Down Expand Up @@ -96,28 +95,28 @@ contract FeeBank is IFeeBank, Ownable {
for (uint256 i = 0; i < accountsLength; ++i) {
address account = accounts[i];
uint256 accountDeposit = _accountDeposits[account];
uint256 availableCredit_ = _charger.availableCredit(account);
uint256 availableCredit_ = _CHARGER.availableCredit(account);
_accountDeposits[account] = availableCredit_;
totalAccountFees += accountDeposit - availableCredit_; // overflow is impossible due to checks in FeeBankCharger
}
}
_token.safeTransfer(msg.sender, totalAccountFees);
_TOKEN.safeTransfer(msg.sender, totalAccountFees);
}

function _depositFor(address account, uint256 amount) internal returns (uint256 totalAvailableCredit) {
if (account == address(0)) revert ZeroAddress();
_token.safeTransferFrom(msg.sender, address(this), amount);
_TOKEN.safeTransferFrom(msg.sender, address(this), amount);
unchecked {
_accountDeposits[account] += amount; // overflow is impossible due to limited _token supply
_accountDeposits[account] += amount; // overflow is impossible due to limited _TOKEN supply
}
totalAvailableCredit = _charger.increaseAvailableCredit(account, amount);
totalAvailableCredit = _CHARGER.increaseAvailableCredit(account, amount);
}

function _withdrawTo(address account, uint256 amount) internal returns (uint256 totalAvailableCredit) {
totalAvailableCredit = _charger.decreaseAvailableCredit(msg.sender, amount);
totalAvailableCredit = _CHARGER.decreaseAvailableCredit(msg.sender, amount);
unchecked {
_accountDeposits[msg.sender] -= amount; // underflow is impossible due to checks in FeeBankCharger
}
_token.safeTransfer(account, amount);
_TOKEN.safeTransfer(account, amount);
}
}
10 changes: 5 additions & 5 deletions contracts/FeeBankCharger.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IFeeBank } from "./interfaces/IFeeBank.sol";
Expand All @@ -18,19 +18,19 @@ contract FeeBankCharger is IFeeBankCharger {
/**
* @notice See {IFeeBankCharger-feeBank}.
*/
IFeeBank public immutable feeBank;
IFeeBank public immutable FEE_BANK;
mapping(address => uint256) private _creditAllowance;

/**
* @dev Modifier to check if the sender is a feeBank contract.
* @dev Modifier to check if the sender is a FEE_BANK contract.
*/
modifier onlyFeeBank() {
if (msg.sender != address(feeBank)) revert OnlyFeeBankAccess();
if (msg.sender != address(FEE_BANK)) revert OnlyFeeBankAccess();
_;
}

constructor(IERC20 token) {
feeBank = new FeeBank(this, token, msg.sender);
FEE_BANK = new FeeBank(this, token, msg.sender);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions contracts/PowerPod.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

import { FarmingDelegationPod } from "@1inch/delegating/contracts/FarmingDelegationPod.sol";
import { FarmingDelegationPlugin } from "@1inch/delegating/contracts/FarmingDelegationPlugin.sol";
import { IVotable } from "@1inch/st1inch/contracts/interfaces/IVotable.sol";
import { ISt1inch } from "@1inch/st1inch/contracts/interfaces/ISt1inch.sol";
import { VotingPowerCalculator } from "@1inch/st1inch/contracts/helpers/VotingPowerCalculator.sol";
Expand All @@ -12,13 +12,13 @@ import { VotingPowerCalculator } from "@1inch/st1inch/contracts/helpers/VotingPo
* @notice The contract combines farming and delegation features of pods with voting power calculations for the participating accounts.
* @dev Limits pods number and the gas usage per pod.
*/
contract PowerPod is FarmingDelegationPod, VotingPowerCalculator, IVotable {
contract PowerPod is FarmingDelegationPlugin, VotingPowerCalculator, IVotable {
uint256 private constant _MAX_SHARE_PODS = 3;
uint256 private constant _SHARE_POD_GAS_LIMIT = 140_000;

constructor(string memory name_, string memory symbol_, ISt1inch st1inch)
FarmingDelegationPod(name_, symbol_, st1inch, _MAX_SHARE_PODS, _SHARE_POD_GAS_LIMIT)
VotingPowerCalculator(st1inch.expBase(), st1inch.origin())
FarmingDelegationPlugin(name_, symbol_, st1inch, _MAX_SHARE_PODS, _SHARE_POD_GAS_LIMIT)
VotingPowerCalculator(st1inch.EXP_BASE(), st1inch.ORIGIN())
{}

/**
Expand Down
10 changes: 5 additions & 5 deletions contracts/SettlementExtension.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
Expand All @@ -27,11 +27,11 @@ contract SettlementExtension is IPostInteraction, IAmountGetter, FeeBankCharger
uint256 private constant _ORDER_FEE_BASE_POINTS = 1e15;
uint256 private constant _BASE_POINTS = 10_000_000; // 100%

IOrderMixin private immutable _limitOrderProtocol;
IOrderMixin private immutable _LIMIT_ORDER_PROTOCOL;

/// @dev Modifier to check if the caller is the limit order protocol contract.
modifier onlyLimitOrderProtocol {
if (msg.sender != address(_limitOrderProtocol)) revert OnlyLimitOrderProtocol();
if (msg.sender != address(_LIMIT_ORDER_PROTOCOL)) revert OnlyLimitOrderProtocol();
_;
}

Expand All @@ -43,7 +43,7 @@ contract SettlementExtension is IPostInteraction, IAmountGetter, FeeBankCharger
constructor(IOrderMixin limitOrderProtocol, IERC20 token)
FeeBankCharger(token)
{
_limitOrderProtocol = limitOrderProtocol;
_LIMIT_ORDER_PROTOCOL = limitOrderProtocol;
}

function getMakingAmount(
Expand All @@ -69,7 +69,7 @@ contract SettlementExtension is IPostInteraction, IAmountGetter, FeeBankCharger
bytes calldata extraData
) external view returns (uint256) {
uint256 rateBump = _getRateBump(extraData);
return Math.mulDiv(order.takingAmount, makingAmount * (_BASE_POINTS + rateBump), order.makingAmount * _BASE_POINTS, Math.Rounding.Up);
return Math.mulDiv(order.takingAmount, makingAmount * (_BASE_POINTS + rateBump), order.makingAmount * _BASE_POINTS, Math.Rounding.Ceil);
}

function postInteraction(
Expand Down
16 changes: 8 additions & 8 deletions contracts/WhitelistRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
Expand Down Expand Up @@ -33,7 +33,7 @@ contract WhitelistRegistry is Ownable {
event Promotion(address promoter, uint256 chainId, address promotee);

uint256 public constant BASIS_POINTS = 10000;
IERC20 public immutable token;
IERC20 public immutable TOKEN;

mapping(address promoter => mapping(uint256 chainId => address promotee)) public promotions;
// 100% = 10000, 10% = 1000, 1% = 100
Expand All @@ -44,8 +44,8 @@ contract WhitelistRegistry is Ownable {
constructor(
IERC20 token_,
uint256 resolverPercentageThreshold_
) {
token = token_;
) Ownable(msg.sender) {
TOKEN = token_;
_setResolverPercentageThreshold(resolverPercentageThreshold_);
}

Expand Down Expand Up @@ -74,8 +74,8 @@ contract WhitelistRegistry is Ownable {
*/
function register() external {
uint256 percentageThreshold = resolverPercentageThreshold;
uint256 totalSupply = token.totalSupply();
if (!_isValidBalance(percentageThreshold, token.balanceOf(msg.sender), totalSupply)) revert BalanceLessThanThreshold();
uint256 totalSupply = TOKEN.totalSupply();
if (!_isValidBalance(percentageThreshold, TOKEN.balanceOf(msg.sender), totalSupply)) revert BalanceLessThanThreshold();
if (!_whitelist.add(msg.sender)) revert AlreadyRegistered();
emit Registered(msg.sender);
_clean(percentageThreshold, totalSupply);
Expand All @@ -96,7 +96,7 @@ contract WhitelistRegistry is Ownable {
* @notice Cleans the whitelist by removing addresses that fall below the resolver threshold.
*/
function clean() external {
_clean(resolverPercentageThreshold, token.totalSupply());
_clean(resolverPercentageThreshold, TOKEN.totalSupply());
}

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ contract WhitelistRegistry is Ownable {
unchecked {
for (uint256 i = 0; i < whitelistLength; ) {
address curWhitelisted = _whitelist.at(i);
uint256 balance = token.balanceOf(curWhitelisted);
uint256 balance = TOKEN.balanceOf(curWhitelisted);
if (!_isValidBalance(percentageThreshold, balance, totalSupply)) {
_removeFromWhitelist(curWhitelisted);
whitelistLength--;
Expand Down
14 changes: 7 additions & 7 deletions contracts/helpers/ResolverMetadata.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

import { ITokenizedDelegationPod } from "@1inch/delegating/contracts/interfaces/ITokenizedDelegationPod.sol";
import { ITokenizedDelegationPlugin } from "@1inch/delegating/contracts/interfaces/ITokenizedDelegationPlugin.sol";

/// @notice Stores resolvers link to their metadata, which is displayed in 1inch dapp.
contract ResolverMetadata {

/// @dev Emitted when an unregistered resolver tries to perform a restricted operation.
error NotRegisteredDelegatee();

ITokenizedDelegationPod public immutable delegation;
mapping(address resolver => string url) public getUrl;
ITokenizedDelegationPlugin public immutable DELEGATION;
mapping (address resolver => string url) public getUrl;

/// @dev Modifier to check if the sender is a registered resolver.
modifier onlyRegistered {
if (address(delegation.registration(msg.sender)) == address(0)) revert NotRegisteredDelegatee();
if (address(DELEGATION.registration(msg.sender)) == address(0)) revert NotRegisteredDelegatee();
_;
}

constructor(ITokenizedDelegationPod delegation_) {
delegation = delegation_;
constructor(ITokenizedDelegationPlugin delegation_) {
DELEGATION = delegation_;
}

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

pragma solidity 0.8.19;
pragma solidity 0.8.23;

interface IFeeBank {
/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IFeeBankCharger.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;
pragma solidity 0.8.23;

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

Expand All @@ -9,7 +9,7 @@ interface IFeeBankCharger {
* @notice Returns the instance of the FeeBank contract.
* @return The instance of the FeeBank contract.
*/
function feeBank() external view returns (IFeeBank);
function FEE_BANK() external view returns (IFeeBank); // solhint-disable-line func-name-mixedcase

/**
* @notice Returns the available credit for a given account.
Expand Down
Loading