From 47de4b8f9472f25865bd3fe9026cf9a8bfa122ba Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Feb 2022 09:01:46 +0000 Subject: [PATCH] Transpile e170b59f --- CHANGELOG.md | 14 +++++++------- contracts/mocks/MathMockUpgradeable.sol | 4 ---- contracts/mocks/SignedMathMockUpgradeable.sol | 4 ++++ contracts/token/common/ERC2981Upgradeable.sol | 8 +++++++- contracts/utils/math/MathUpgradeable.sol | 10 ---------- contracts/utils/math/SignedMathUpgradeable.sol | 10 ++++++++++ test/utils/math/Math.test.js | 18 +----------------- test/utils/math/SignedMath.test.js | 16 ++++++++++++++++ 8 files changed, 45 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6f895c27..a353c08c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,8 @@ ## 4.5.0 - * `ERC2891`: add implementation of the royalty standard, and the respective extensions for `ERC721` and `ERC1155`. ([#3012](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3012)) + * `ERC2981`: add implementation of the royalty standard, and the respective extensions for `ERC721` and `ERC1155`. ([#3012](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3012)) * `GovernorTimelockControl`: improve the `state()` function to have it reflect cases where a proposal has been canceled directly on the timelock. ([#2977](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2977)) - * `Math`: add a `abs(int256)` method that returns the unsigned absolute value of a signed value. ([#2984](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2984)) * Preset contracts are now deprecated in favor of [Contracts Wizard](https://wizard.openzeppelin.com). ([#2986](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2986)) * `Governor`: add a relay function to help recover assets sent to a governor that is not its own executor (e.g. when using a timelock). ([#2926](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2926)) * `GovernorPreventLateQuorum`: add new module to ensure a minimum voting duration is available after the quorum is reached. ([#2973](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2973)) @@ -12,11 +11,12 @@ * `Votes`: Added a base contract for vote tracking with delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944)) * `ERC721Votes`: Added an extension of ERC721 enabled with vote tracking and delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944)) * `ERC2771Context`: use immutable storage to store the forwarder address, no longer an issue since Solidity >=0.8.8 allows reading immutable variables in the constructor. ([#2917](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2917)) - * `Base64`: add a library to parse bytes into base64 strings using `encode(bytes memory)` function, and provide examples to show how to use to build URL-safe `tokenURIs`. ([#2884](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2884)) - * `ERC20`: reduce allowance before triggering transfer. ([#3056](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#3056)) - * `ERC20`: do not update allowance on `transferFrom` when allowance is `type(uint256).max`. ([#3085](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#3085)) - * `ERC777`: do not update allowance on `transferFrom` when allowance is `type(uint256).max`. ([#3085](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#3085)) + * `Base64`: add a library to parse bytes into base64 strings using `encode(bytes memory)` function, and provide examples to show how to use to build URL-safe `tokenURIs`. ([#2884](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2884)) + * `ERC20`: reduce allowance before triggering transfer. ([#3056](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3056)) + * `ERC20`: do not update allowance on `transferFrom` when allowance is `type(uint256).max`. ([#3085](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3085)) + * `ERC777`: do not update allowance on `transferFrom` when allowance is `type(uint256).max`. ([#3085](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3085)) * `SignedMath`: a new signed version of the Math library with `max`, `min`, and `average`. ([#2686](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2686)) + * `SignedMath`: add a `abs(int256)` method that returns the unsigned absolute value of a signed value. ([#2984](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2984)) * `ERC1967Upgrade`: Refactor the secure upgrade to use `ERC1822` instead of the previous rollback mechanism. This reduces code complexity and attack surface with similar security guarantees. ([#3021](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3021)) * `UUPSUpgradeable`: Add `ERC1822` compliance to support the updated secure upgrade mechanism. ([#3021](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3021)) * Some more functions have been made virtual to customize them via overrides. In many cases this will not imply that other functions in the contract will automatically adapt to the overridden definitions. People who wish to override should consult the source code to understand the impact and if they need to override any additional functions to achieve the desired behavior. @@ -29,7 +29,7 @@ ## 4.4.2 (2022-01-11) ### Bugfixes - * `GovernorCompatibilityBravo`: Fix error in the encoding of calldata for proposals submitted through the compatibility interface with explicit signatures. ([#3100](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#3100)) + * `GovernorCompatibilityBravo`: Fix error in the encoding of calldata for proposals submitted through the compatibility interface with explicit signatures. ([#3100](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3100)) ## 4.4.1 (2021-12-14) diff --git a/contracts/mocks/MathMockUpgradeable.sol b/contracts/mocks/MathMockUpgradeable.sol index 1fcb9de05..2bb032b61 100644 --- a/contracts/mocks/MathMockUpgradeable.sol +++ b/contracts/mocks/MathMockUpgradeable.sol @@ -27,10 +27,6 @@ contract MathMockUpgradeable is Initializable { return MathUpgradeable.ceilDiv(a, b); } - function abs(int256 n) public pure returns (uint256) { - return MathUpgradeable.abs(n); - } - /** * This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. diff --git a/contracts/mocks/SignedMathMockUpgradeable.sol b/contracts/mocks/SignedMathMockUpgradeable.sol index 13e5c835f..fa104349b 100644 --- a/contracts/mocks/SignedMathMockUpgradeable.sol +++ b/contracts/mocks/SignedMathMockUpgradeable.sol @@ -23,6 +23,10 @@ contract SignedMathMockUpgradeable is Initializable { return SignedMathUpgradeable.average(a, b); } + function abs(int256 n) public pure returns (uint256) { + return SignedMathUpgradeable.abs(n); + } + /** * This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. diff --git a/contracts/token/common/ERC2981Upgradeable.sol b/contracts/token/common/ERC2981Upgradeable.sol index 17e0865e8..7eb163aee 100644 --- a/contracts/token/common/ERC2981Upgradeable.sol +++ b/contracts/token/common/ERC2981Upgradeable.sol @@ -46,7 +46,13 @@ abstract contract ERC2981Upgradeable is Initializable, IERC2981Upgradeable, ERC1 /** * @inheritdoc IERC2981Upgradeable */ - function royaltyInfo(uint256 _tokenId, uint256 _salePrice) external view override returns (address, uint256) { + function royaltyInfo(uint256 _tokenId, uint256 _salePrice) + external + view + virtual + override + returns (address, uint256) + { RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId]; if (royalty.receiver == address(0)) { diff --git a/contracts/utils/math/MathUpgradeable.sol b/contracts/utils/math/MathUpgradeable.sol index e58eb02e1..24c7ee96f 100644 --- a/contracts/utils/math/MathUpgradeable.sol +++ b/contracts/utils/math/MathUpgradeable.sol @@ -40,14 +40,4 @@ library MathUpgradeable { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } - - /** - * @dev Returns the absolute unsigned value of a signed value. - */ - function abs(int256 n) internal pure returns (uint256) { - unchecked { - // must be unchecked in order to support `n = type(int256).min` - return uint256(n >= 0 ? n : -n); - } - } } diff --git a/contracts/utils/math/SignedMathUpgradeable.sol b/contracts/utils/math/SignedMathUpgradeable.sol index d4f7d196f..70eb10a17 100644 --- a/contracts/utils/math/SignedMathUpgradeable.sol +++ b/contracts/utils/math/SignedMathUpgradeable.sol @@ -30,4 +30,14 @@ library SignedMathUpgradeable { int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } + + /** + * @dev Returns the absolute unsigned value of a signed value. + */ + function abs(int256 n) internal pure returns (uint256) { + unchecked { + // must be unchecked in order to support `n = type(int256).min` + return uint256(n >= 0 ? n : -n); + } + } } diff --git a/test/utils/math/Math.test.js b/test/utils/math/Math.test.js index eff64b720..7e194dec7 100644 --- a/test/utils/math/Math.test.js +++ b/test/utils/math/Math.test.js @@ -1,6 +1,6 @@ const { BN, constants } = require('@openzeppelin/test-helpers'); const { expect } = require('chai'); -const { MAX_UINT256, MAX_INT256, MIN_INT256 } = constants; +const { MAX_UINT256 } = constants; const MathMock = artifacts.require('MathMock'); @@ -85,20 +85,4 @@ contract('Math', function (accounts) { expect(await this.math.ceilDiv(MAX_UINT256, b)).to.be.bignumber.equal(MAX_UINT256); }); }); - - describe('abs', function () { - for (const n of [ - MIN_INT256, - MIN_INT256.addn(1), - new BN('-1'), - new BN('0'), - new BN('1'), - MAX_INT256.subn(1), - MAX_INT256, - ]) { - it(`correctly computes the absolute value of ${n}`, async function () { - expect(await this.math.abs(n)).to.be.bignumber.equal(n.abs()); - }); - } - }); }); diff --git a/test/utils/math/SignedMath.test.js b/test/utils/math/SignedMath.test.js index 0aef556df..8e9826f02 100644 --- a/test/utils/math/SignedMath.test.js +++ b/test/utils/math/SignedMath.test.js @@ -74,4 +74,20 @@ contract('SignedMath', function (accounts) { } }); }); + + describe('abs', function () { + for (const n of [ + MIN_INT256, + MIN_INT256.addn(1), + new BN('-1'), + new BN('0'), + new BN('1'), + MAX_INT256.subn(1), + MAX_INT256, + ]) { + it(`correctly computes the absolute value of ${n}`, async function () { + expect(await this.math.abs(n)).to.be.bignumber.equal(n.abs()); + }); + } + }); });