Skip to content

Commit

Permalink
Merge branch 'master' into feature/environment-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Sep 29, 2022
2 parents dc79be3 + c8d596b commit ed0bb7c
Show file tree
Hide file tree
Showing 38 changed files with 1,796 additions and 1,298 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist
typechain-types
.DS_Store
*.log
mochaOutput.json
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore artifacts:
node_modules
dist
typechain-types
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120
}
},
{
"files": "*.js",
"options": {
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
}
}
]
}
4 changes: 3 additions & 1 deletion contracts/GasChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ contract GasChecker {
modifier checkGasCost(uint256 expected) {
uint256 gas = gasleft();
_;
unchecked { gas -= gasleft(); }
unchecked {
gas -= gasleft();
}
if (expected > 0 && gas != expected) revert GasCostDiffers(expected, gas);
}
}
2 changes: 1 addition & 1 deletion contracts/OnlyWethReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma abicoder v1;
import "./EthReceiver.sol";

abstract contract OnlyWethReceiver is EthReceiver {
address private immutable _WETH; // solhint-disable-line var-name-mixedcase
address private immutable _WETH; // solhint-disable-line var-name-mixedcase

constructor(address weth) {
_WETH = address(weth);
Expand Down
12 changes: 10 additions & 2 deletions contracts/interfaces/IDaiLikePermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
pragma solidity ^0.8.0;
pragma abicoder v1;


interface IDaiLikePermit {
function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external;
function permit(
address holder,
address spender,
uint256 nonce,
uint256 expiry,
bool allowed,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
6 changes: 3 additions & 3 deletions contracts/interfaces/IERC20MetadataUppercase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
pragma solidity ^0.8.0;
pragma abicoder v1;


interface IERC20MetadataUppercase {
function NAME() external view returns (string memory); // solhint-disable-line func-name-mixedcase
function SYMBOL() external view returns (string memory); // solhint-disable-line func-name-mixedcase
function NAME() external view returns (string memory); // solhint-disable-line func-name-mixedcase

function SYMBOL() external view returns (string memory); // solhint-disable-line func-name-mixedcase
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pragma abicoder v1;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";


interface IWETH is IERC20 {
function deposit() external payable;

function withdraw(uint256 amount) external;
}
39 changes: 27 additions & 12 deletions contracts/libraries/AddressArray.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,73 @@
pragma solidity ^0.8.0;
pragma abicoder v1;

/// @title Library that implements address array on mapping, stores array length at 0 index.
library AddressArray {
error IndexOutOfBounds();
error PopFromEmptyArray();
error OutputArrayTooSmall();

/// @dev Data struct containing raw mapping.
struct Data {
mapping(uint256 => uint256) _raw;
}

function length(Data storage self) internal view returns(uint256) {
/// @dev Length of array.
function length(Data storage self) internal view returns (uint256) {
return self._raw[0] >> 160;
}

function at(Data storage self, uint i) internal view returns(address) {
/// @dev Returns data item from `self` storage at `i`.
function at(Data storage self, uint256 i) internal view returns (address) {
return address(uint160(self._raw[i]));
}

function get(Data storage self) internal view returns(address[] memory arr) {
/// @dev Returns list of addresses from storage `self`.
function get(Data storage self) internal view returns (address[] memory arr) {
uint256 lengthAndFirst = self._raw[0];
arr = new address[](lengthAndFirst >> 160);
_get(self, arr, lengthAndFirst);
}

function get(Data storage self, address[] memory output) internal view returns(address[] memory) {
/// @dev Puts list of addresses from `self` storage into `output` array.
function get(Data storage self, address[] memory output) internal view returns (address[] memory) {
return _get(self, output, self._raw[0]);
}

function _get(Data storage self, address[] memory output, uint256 lengthAndFirst) private view returns(address[] memory) {
function _get(
Data storage self,
address[] memory output,
uint256 lengthAndFirst
) private view returns (address[] memory) {
uint256 len = lengthAndFirst >> 160;
if (len > output.length) revert OutputArrayTooSmall();
if (len > 0) {
output[0] = address(uint160(lengthAndFirst));
unchecked {
for (uint i = 1; i < len; i++) {
for (uint256 i = 1; i < len; i++) {
output[i] = address(uint160(self._raw[i]));
}
}
}
return output;
}

function push(Data storage self, address account) internal returns(uint256) {
/// @dev Array push back `account` operation on storage `self`.
function push(Data storage self, address account) internal returns (uint256) {
unchecked {
uint256 lengthAndFirst = self._raw[0];
uint256 len = lengthAndFirst >> 160;
if (len == 0) {
self._raw[0] = (1 << 160) + uint160(account);
}
else {
} else {
self._raw[0] = lengthAndFirst + (1 << 160);
self._raw[len] = uint160(account);
}
return len + 1;
}
}

/// @dev Array pop back operation for storage `self`.
function pop(Data storage self) internal {
unchecked {
uint256 lengthAndFirst = self._raw[0];
Expand All @@ -71,14 +82,18 @@ library AddressArray {
}
}

function set(Data storage self, uint256 index, address account) internal {
/// @dev Set element for storage `self` at `index` to `account`.
function set(
Data storage self,
uint256 index,
address account
) internal {
uint256 len = length(self);
if (index >= len) revert IndexOutOfBounds();

if (index == 0) {
self._raw[0] = (len << 160) | uint160(account);
}
else {
} else {
self._raw[index] = uint160(account);
}
}
Expand Down
26 changes: 20 additions & 6 deletions contracts/libraries/AddressSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,50 @@ pragma abicoder v1;

import "./AddressArray.sol";

/** @title Library that is using AddressArray library for AddressArray.Data
* and allows Set operations on address storage data:
* 1. add
* 2. remove
* 3. contains
*/
library AddressSet {
using AddressArray for AddressArray.Data;

/** @dev Data struct from AddressArray.Data items
* and lookup mapping address => index in data array.
*/
struct Data {
AddressArray.Data items;
mapping(address => uint256) lookup;
}

function length(Data storage s) internal view returns(uint) {
/// @dev Length of data storage.
function length(Data storage s) internal view returns (uint256) {
return s.items.length();
}

function at(Data storage s, uint index) internal view returns(address) {
/// @dev Returns data item from `s` storage at `index`.
function at(Data storage s, uint256 index) internal view returns (address) {
return s.items.at(index);
}

function contains(Data storage s, address item) internal view returns(bool) {
/// @dev Returns true if storage `s` has `item`.
function contains(Data storage s, address item) internal view returns (bool) {
return s.lookup[item] != 0;
}

function add(Data storage s, address item) internal returns(bool) {
/// @dev Adds `item` into storage `s` and returns true if successful.
function add(Data storage s, address item) internal returns (bool) {
if (s.lookup[item] > 0) {
return false;
}
s.lookup[item] = s.items.push(item);
return true;
}

function remove(Data storage s, address item) internal returns(bool) {
uint index = s.lookup[item];
/// @dev Removes `item` from storage `s` and returns true if successful.
function remove(Data storage s, address item) internal returns (bool) {
uint256 index = s.lookup[item];
if (index == 0) {
return false;
}
Expand Down
Loading

0 comments on commit ed0bb7c

Please sign in to comment.