diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4f1b1da..623c157cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ # Changelog -## 4.7.0 +## 4.7.0 (2022-06-29) * `TimelockController`: Migrate `_call` to `_execute` and allow inheritance and overriding similar to `Governor`. ([#3317](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3317)) * `CrossChainEnabledPolygonChild`: replace the `require` statement with the custom error `NotCrossChainCall`. ([#3380](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3380)) * `ERC20FlashMint`: Add customizable flash fee receiver. ([#3327](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3327)) - * `ERC20TokenizedVault`: add an extension of `ERC20` that implements the ERC4626 Tokenized Vault Standard. ([#3171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3171)) + * `ERC4626`: add an extension of `ERC20` that implements the ERC4626 Tokenized Vault Standard. ([#3171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3171)) * `SafeERC20`: add `safePermit` as mitigation against phantom permit functions. ([#3280](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3280)) * `Math`: add a `mulDiv` function that can round the result either up or down. ([#3171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3171)) * `Math`: Add a `sqrt` function to compute square roots of integers, rounding either up or down. ([#3242](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3242)) diff --git a/contracts/access/AccessControlUpgradeable.sol b/contracts/access/AccessControlUpgradeable.sol index 3792befb6..d579dafbf 100644 --- a/contracts/access/AccessControlUpgradeable.sol +++ b/contracts/access/AccessControlUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (access/AccessControl.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol) pragma solidity ^0.8.0; diff --git a/contracts/access/OwnableUpgradeable.sol b/contracts/access/OwnableUpgradeable.sol index 5be8fe17d..affb7cdcb 100644 --- a/contracts/access/OwnableUpgradeable.sol +++ b/contracts/access/OwnableUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (access/Ownable.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; diff --git a/contracts/crosschain/amb/CrossChainEnabledAMBUpgradeable.sol b/contracts/crosschain/amb/CrossChainEnabledAMBUpgradeable.sol index f11be30a7..687e21248 100644 --- a/contracts/crosschain/amb/CrossChainEnabledAMBUpgradeable.sol +++ b/contracts/crosschain/amb/CrossChainEnabledAMBUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/amb/CrossChainEnabledAMB.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/amb/CrossChainEnabledAMB.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/amb/LibAMBUpgradeable.sol b/contracts/crosschain/amb/LibAMBUpgradeable.sol index 97cdb20c4..b5f32d0d4 100644 --- a/contracts/crosschain/amb/LibAMBUpgradeable.sol +++ b/contracts/crosschain/amb/LibAMBUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/amb/LibAMB.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/amb/LibAMB.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1Upgradeable.sol b/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1Upgradeable.sol index dd7515865..afbb030ef 100644 --- a/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1Upgradeable.sol +++ b/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2Upgradeable.sol b/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2Upgradeable.sol index 6fab7132e..477935265 100644 --- a/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2Upgradeable.sol +++ b/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/arbitrum/CrossChainEnabledArbitrumL2.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/arbitrum/CrossChainEnabledArbitrumL2.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/arbitrum/LibArbitrumL1Upgradeable.sol b/contracts/crosschain/arbitrum/LibArbitrumL1Upgradeable.sol index b8c1b694c..0a104e835 100644 --- a/contracts/crosschain/arbitrum/LibArbitrumL1Upgradeable.sol +++ b/contracts/crosschain/arbitrum/LibArbitrumL1Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/arbitrum/LibArbitrumL1.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/arbitrum/LibArbitrumL1.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/arbitrum/LibArbitrumL2Upgradeable.sol b/contracts/crosschain/arbitrum/LibArbitrumL2Upgradeable.sol index c2cc5bc15..a5091fa1c 100644 --- a/contracts/crosschain/arbitrum/LibArbitrumL2Upgradeable.sol +++ b/contracts/crosschain/arbitrum/LibArbitrumL2Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/arbitrum/LibArbitrumL2.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/arbitrum/LibArbitrumL2.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/optimism/CrossChainEnabledOptimismUpgradeable.sol b/contracts/crosschain/optimism/CrossChainEnabledOptimismUpgradeable.sol index 172a3cb08..f7fa9732d 100644 --- a/contracts/crosschain/optimism/CrossChainEnabledOptimismUpgradeable.sol +++ b/contracts/crosschain/optimism/CrossChainEnabledOptimismUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/optimism/CrossChainEnabledOptimism.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/optimism/CrossChainEnabledOptimism.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/optimism/LibOptimismUpgradeable.sol b/contracts/crosschain/optimism/LibOptimismUpgradeable.sol index a5195ad4c..b1260dd4d 100644 --- a/contracts/crosschain/optimism/LibOptimismUpgradeable.sol +++ b/contracts/crosschain/optimism/LibOptimismUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/optimism/LibOptimism.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/optimism/LibOptimism.sol) pragma solidity ^0.8.4; diff --git a/contracts/crosschain/polygon/CrossChainEnabledPolygonChildUpgradeable.sol b/contracts/crosschain/polygon/CrossChainEnabledPolygonChildUpgradeable.sol index 8e2bebbb8..862e484c3 100644 --- a/contracts/crosschain/polygon/CrossChainEnabledPolygonChildUpgradeable.sol +++ b/contracts/crosschain/polygon/CrossChainEnabledPolygonChildUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (crosschain/polygon/CrossChainEnabledPolygonChild.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/polygon/CrossChainEnabledPolygonChild.sol) pragma solidity ^0.8.4; diff --git a/contracts/finance/PaymentSplitterUpgradeable.sol b/contracts/finance/PaymentSplitterUpgradeable.sol index 5211e786a..b92265c60 100644 --- a/contracts/finance/PaymentSplitterUpgradeable.sol +++ b/contracts/finance/PaymentSplitterUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (finance/PaymentSplitter.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (finance/PaymentSplitter.sol) pragma solidity ^0.8.0; @@ -15,7 +15,8 @@ import "../proxy/utils/Initializable.sol"; * * The split can be in equal parts or in any other arbitrary proportion. The way this is specified is by assigning each * account to a number of shares. Of all the Ether that this contract receives, each account will then be able to claim - * an amount proportional to the percentage of total shares they were assigned. + * an amount proportional to the percentage of total shares they were assigned. The distribution of shares is set at the + * time of contract deployment and can't be updated thereafter. * * `PaymentSplitter` follows a _pull payment_ model. This means that payments are not automatically forwarded to the * accounts but kept in this contract, and the actual transfer is triggered as a separate step by calling the {release} diff --git a/contracts/finance/VestingWalletUpgradeable.sol b/contracts/finance/VestingWalletUpgradeable.sol index 74bb790ac..b48ec0ae3 100644 --- a/contracts/finance/VestingWalletUpgradeable.sol +++ b/contracts/finance/VestingWalletUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (finance/VestingWallet.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (finance/VestingWallet.sol) pragma solidity ^0.8.0; import "../token/ERC20/utils/SafeERC20Upgradeable.sol"; diff --git a/contracts/governance/GovernorUpgradeable.sol b/contracts/governance/GovernorUpgradeable.sol index 3c61758af..e5c8c8609 100644 --- a/contracts/governance/GovernorUpgradeable.sol +++ b/contracts/governance/GovernorUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (governance/Governor.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (governance/Governor.sol) pragma solidity ^0.8.0; diff --git a/contracts/governance/IGovernorUpgradeable.sol b/contracts/governance/IGovernorUpgradeable.sol index 327946736..3dfa4c60c 100644 --- a/contracts/governance/IGovernorUpgradeable.sol +++ b/contracts/governance/IGovernorUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (governance/IGovernor.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (governance/IGovernor.sol) pragma solidity ^0.8.0; diff --git a/contracts/governance/TimelockControllerUpgradeable.sol b/contracts/governance/TimelockControllerUpgradeable.sol index 4cef607f5..2458bacca 100644 --- a/contracts/governance/TimelockControllerUpgradeable.sol +++ b/contracts/governance/TimelockControllerUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (governance/TimelockController.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (governance/TimelockController.sol) pragma solidity ^0.8.0; diff --git a/contracts/interfaces/IERC3156FlashBorrowerUpgradeable.sol b/contracts/interfaces/IERC3156FlashBorrowerUpgradeable.sol index 84d6bb165..3f75175ca 100644 --- a/contracts/interfaces/IERC3156FlashBorrowerUpgradeable.sol +++ b/contracts/interfaces/IERC3156FlashBorrowerUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (interfaces/IERC3156FlashBorrower.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC3156FlashBorrower.sol) pragma solidity ^0.8.0; diff --git a/contracts/interfaces/IERC4626Upgradeable.sol b/contracts/interfaces/IERC4626Upgradeable.sol index 14cd31c27..0fcb3ece7 100644 --- a/contracts/interfaces/IERC4626Upgradeable.sol +++ b/contracts/interfaces/IERC4626Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (interfaces/IERC4626.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC4626.sol) pragma solidity ^0.8.0; diff --git a/contracts/metatx/ERC2771ContextUpgradeable.sol b/contracts/metatx/ERC2771ContextUpgradeable.sol index c7206e17c..3850112e0 100644 --- a/contracts/metatx/ERC2771ContextUpgradeable.sol +++ b/contracts/metatx/ERC2771ContextUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (metatx/ERC2771Context.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (metatx/ERC2771Context.sol) pragma solidity ^0.8.9; diff --git a/contracts/metatx/MinimalForwarderUpgradeable.sol b/contracts/metatx/MinimalForwarderUpgradeable.sol index d8699f5f9..a93b415e0 100644 --- a/contracts/metatx/MinimalForwarderUpgradeable.sol +++ b/contracts/metatx/MinimalForwarderUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (metatx/MinimalForwarder.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (metatx/MinimalForwarder.sol) pragma solidity ^0.8.0; diff --git a/contracts/mocks/ERC20TokenizedVaultMockUpgradeable.sol b/contracts/mocks/ERC4626MockUpgradeable.sol similarity index 74% rename from contracts/mocks/ERC20TokenizedVaultMockUpgradeable.sol rename to contracts/mocks/ERC4626MockUpgradeable.sol index 0e5750073..84cd9d652 100644 --- a/contracts/mocks/ERC20TokenizedVaultMockUpgradeable.sol +++ b/contracts/mocks/ERC4626MockUpgradeable.sol @@ -2,21 +2,21 @@ pragma solidity ^0.8.0; -import "../token/ERC20/extensions/ERC20TokenizedVaultUpgradeable.sol"; +import "../token/ERC20/extensions/ERC4626Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; // mock class using ERC20 -contract ERC20TokenizedVaultMockUpgradeable is Initializable, ERC20TokenizedVaultUpgradeable { - function __ERC20TokenizedVaultMock_init( +contract ERC4626MockUpgradeable is Initializable, ERC4626Upgradeable { + function __ERC4626Mock_init( IERC20MetadataUpgradeable asset, string memory name, string memory symbol ) internal onlyInitializing { __ERC20_init_unchained(name, symbol); - __ERC20TokenizedVault_init_unchained(asset); + __ERC4626_init_unchained(asset); } - function __ERC20TokenizedVaultMock_init_unchained( + function __ERC4626Mock_init_unchained( IERC20MetadataUpgradeable, string memory, string memory diff --git a/contracts/mocks/MerkleProofWrapperUpgradeable.sol b/contracts/mocks/MerkleProofWrapperUpgradeable.sol index 3769079d8..c45120ac0 100644 --- a/contracts/mocks/MerkleProofWrapperUpgradeable.sol +++ b/contracts/mocks/MerkleProofWrapperUpgradeable.sol @@ -36,20 +36,37 @@ contract MerkleProofWrapperUpgradeable is Initializable { } function multiProofVerify( + bytes32[] memory proofs, + bool[] memory proofFlag, + bytes32 root, + bytes32[] memory leaves + ) public pure returns (bool) { + return MerkleProofUpgradeable.multiProofVerify(proofs, proofFlag, root, leaves); + } + + function multiProofVerifyCalldata( bytes32[] calldata proofs, bool[] calldata proofFlag, bytes32 root, - bytes32[] calldata leaves + bytes32[] memory leaves ) public pure returns (bool) { - return MerkleProofUpgradeable.multiProofVerify(proofs, proofFlag, root, leaves); + return MerkleProofUpgradeable.multiProofVerifyCalldata(proofs, proofFlag, root, leaves); } function processMultiProof( + bytes32[] memory proofs, + bool[] memory proofFlag, + bytes32[] memory leaves + ) public pure returns (bytes32) { + return MerkleProofUpgradeable.processMultiProof(proofs, proofFlag, leaves); + } + + function processMultiProofCalldata( bytes32[] calldata proofs, bool[] calldata proofFlag, - bytes32[] calldata leaves + bytes32[] memory leaves ) public pure returns (bytes32) { - return MerkleProofUpgradeable.processMultiProof(proofs, proofFlag, leaves); + return MerkleProofUpgradeable.processMultiProofCalldata(proofs, proofFlag, leaves); } /** diff --git a/contracts/mocks/WithInit.sol b/contracts/mocks/WithInit.sol index 478f04807..8ea2ba590 100644 --- a/contracts/mocks/WithInit.sol +++ b/contracts/mocks/WithInit.sol @@ -206,135 +206,153 @@ contract MathMockUpgradeableWithInit is MathMockUpgradeable { __MathMock_init(); } } -import "./ERC20SnapshotMockUpgradeable.sol"; +import "./ERC20WrapperMockUpgradeable.sol"; -contract ERC20SnapshotMockUpgradeableWithInit is ERC20SnapshotMockUpgradeable { +contract ERC20WrapperMockUpgradeableWithInit is ERC20WrapperMockUpgradeable { + constructor( + IERC20Upgradeable _underlyingToken, + string memory name, + string memory symbol + ) payable initializer { + __ERC20WrapperMock_init(_underlyingToken, name, symbol); + } +} +import "./ERC20PausableMockUpgradeable.sol"; + +contract ERC20PausableMockUpgradeableWithInit is ERC20PausableMockUpgradeable { constructor( string memory name, string memory symbol, address initialAccount, uint256 initialBalance ) payable initializer { - __ERC20SnapshotMock_init(name, symbol, initialAccount, initialBalance); + __ERC20PausableMock_init(name, symbol, initialAccount, initialBalance); } } -import "./ArraysImplUpgradeable.sol"; +import "./ERC20MockUpgradeable.sol"; -contract ArraysImplUpgradeableWithInit is ArraysImplUpgradeable { - constructor(uint256[] memory array) payable initializer { - __ArraysImpl_init(array); +contract ERC20MockUpgradeableWithInit is ERC20MockUpgradeable { + constructor( + string memory name, + string memory symbol, + address initialAccount, + uint256 initialBalance + ) payable initializer { + __ERC20Mock_init(name, symbol, initialAccount, initialBalance); } } -import "./CheckpointsImplUpgradeable.sol"; +import "./MulticallTokenMockUpgradeable.sol"; -contract CheckpointsImplUpgradeableWithInit is CheckpointsImplUpgradeable { - constructor() payable initializer { - __CheckpointsImpl_init(); +contract MulticallTokenMockUpgradeableWithInit is MulticallTokenMockUpgradeable { + constructor(uint256 initialBalance) payable initializer { + __MulticallTokenMock_init(initialBalance); } } -import "./SafeCastMockUpgradeable.sol"; +import "./MulticallTestUpgradeable.sol"; -contract SafeCastMockUpgradeableWithInit is SafeCastMockUpgradeable { +contract MulticallTestUpgradeableWithInit is MulticallTestUpgradeable { constructor() payable initializer { - __SafeCastMock_init(); + __MulticallTest_init(); } } -import "./GovernorTimelockCompoundMockUpgradeable.sol"; +import "./ERC3156FlashBorrowerMockUpgradeable.sol"; -contract GovernorTimelockCompoundMockUpgradeableWithInit is GovernorTimelockCompoundMockUpgradeable { +contract ERC3156FlashBorrowerMockUpgradeableWithInit is ERC3156FlashBorrowerMockUpgradeable { + constructor(bool enableReturn, bool enableApprove) payable initializer { + __ERC3156FlashBorrowerMock_init(enableReturn, enableApprove); + } +} +import "../token/ERC777/ERC777Upgradeable.sol"; + +contract ERC777UpgradeableWithInit is ERC777Upgradeable { constructor( string memory name_, - IVotesUpgradeable token_, - uint256 votingDelay_, - uint256 votingPeriod_, - ICompoundTimelockUpgradeable timelock_, - uint256 quorumNumerator_ + string memory symbol_, + address[] memory defaultOperators_ ) payable initializer { - __GovernorTimelockCompoundMock_init(name_, token_, votingDelay_, votingPeriod_, timelock_, quorumNumerator_); + __ERC777_init(name_, symbol_, defaultOperators_); } } -import "./wizard/MyGovernor3Upgradeable.sol"; +import "../token/ERC777/presets/ERC777PresetFixedSupplyUpgradeable.sol"; -contract MyGovernorUpgradeableWithInit is MyGovernorUpgradeable { - constructor(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock) payable initializer { - __MyGovernor_init(_token, _timelock); +contract ERC777PresetFixedSupplyUpgradeableWithInit is ERC777PresetFixedSupplyUpgradeable { + constructor( + string memory name, + string memory symbol, + address[] memory defaultOperators, + uint256 initialSupply, + address owner + ) payable initializer { + __ERC777PresetFixedSupply_init(name, symbol, defaultOperators, initialSupply, owner); } } -import "./wizard/MyGovernor2Upgradeable.sol"; +import "./ERC777SenderRecipientMockUpgradeable.sol"; -contract MyGovernor2UpgradeableWithInit is MyGovernor2Upgradeable { - constructor(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock) payable initializer { - __MyGovernor2_init(_token, _timelock); +contract ERC777SenderRecipientMockUpgradeableWithInit is ERC777SenderRecipientMockUpgradeable { + constructor() payable initializer { + __ERC777SenderRecipientMock_init(); } } -import "./wizard/MyGovernor1Upgradeable.sol"; +import "../utils/introspection/ERC1820ImplementerUpgradeable.sol"; -contract MyGovernor1UpgradeableWithInit is MyGovernor1Upgradeable { - constructor(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock) payable initializer { - __MyGovernor1_init(_token, _timelock); +contract ERC1820ImplementerUpgradeableWithInit is ERC1820ImplementerUpgradeable { + constructor() payable initializer { + __ERC1820Implementer_init(); } } -import "./GovernorWithParamsMockUpgradeable.sol"; +import "./ERC1820ImplementerMockUpgradeable.sol"; -contract GovernorWithParamsMockUpgradeableWithInit is GovernorWithParamsMockUpgradeable { - constructor(string memory name_, IVotesUpgradeable token_) payable initializer { - __GovernorWithParamsMock_init(name_, token_); +contract ERC1820ImplementerMockUpgradeableWithInit is ERC1820ImplementerMockUpgradeable { + constructor() payable initializer { + __ERC1820ImplementerMock_init(); } } -import "./GovernorVoteMockUpgradeable.sol"; +import "./Create2ImplUpgradeable.sol"; -contract GovernorVoteMocksUpgradeableWithInit is GovernorVoteMocksUpgradeable { - constructor(string memory name_, IVotesUpgradeable token_) payable initializer { - __GovernorVoteMocks_init(name_, token_); +contract Create2ImplUpgradeableWithInit is Create2ImplUpgradeable { + constructor() payable initializer { + __Create2Impl_init(); } } -import "./GovernorTimelockControlMockUpgradeable.sol"; +import "./ERC777MockUpgradeable.sol"; -contract GovernorTimelockControlMockUpgradeableWithInit is GovernorTimelockControlMockUpgradeable { +contract ERC777MockUpgradeableWithInit is ERC777MockUpgradeable { constructor( - string memory name_, - IVotesUpgradeable token_, - uint256 votingDelay_, - uint256 votingPeriod_, - TimelockControllerUpgradeable timelock_, - uint256 quorumNumerator_ + address initialHolder, + uint256 initialBalance, + string memory name, + string memory symbol, + address[] memory defaultOperators ) payable initializer { - __GovernorTimelockControlMock_init(name_, token_, votingDelay_, votingPeriod_, timelock_, quorumNumerator_); + __ERC777Mock_init(initialHolder, initialBalance, name, symbol, defaultOperators); } } -import "./GovernorPreventLateQuorumMockUpgradeable.sol"; +import "./ERC165CheckerMockUpgradeable.sol"; -contract GovernorPreventLateQuorumMockUpgradeableWithInit is GovernorPreventLateQuorumMockUpgradeable { - constructor( - string memory name_, - IVotesUpgradeable token_, - uint256 votingDelay_, - uint256 votingPeriod_, - uint256 quorum_, - uint64 voteExtension_ - ) payable initializer { - __GovernorPreventLateQuorumMock_init(name_, token_, votingDelay_, votingPeriod_, quorum_, voteExtension_); +contract ERC165CheckerMockUpgradeableWithInit is ERC165CheckerMockUpgradeable { + constructor() payable initializer { + __ERC165CheckerMock_init(); } } -import "./GovernorCompMockUpgradeable.sol"; +import "./ERC165/ERC165InterfacesSupportedUpgradeable.sol"; -contract GovernorCompMockUpgradeableWithInit is GovernorCompMockUpgradeable { - constructor(string memory name_, ERC20VotesCompUpgradeable token_) payable initializer { - __GovernorCompMock_init(name_, token_); +contract SupportsInterfaceWithLookupMockUpgradeableWithInit is SupportsInterfaceWithLookupMockUpgradeable { + constructor() payable initializer { + __SupportsInterfaceWithLookupMock_init(); } } -import "./GovernorCompatibilityBravoMockUpgradeable.sol"; +import "./ERC165/ERC165InterfacesSupportedUpgradeable.sol"; -contract GovernorCompatibilityBravoMockUpgradeableWithInit is GovernorCompatibilityBravoMockUpgradeable { - constructor( - string memory name_, - ERC20VotesCompUpgradeable token_, - uint256 votingDelay_, - uint256 votingPeriod_, - uint256 proposalThreshold_, - ICompoundTimelockUpgradeable timelock_ - ) payable initializer { - __GovernorCompatibilityBravoMock_init(name_, token_, votingDelay_, votingPeriod_, proposalThreshold_, timelock_); +contract ERC165InterfacesSupportedUpgradeableWithInit is ERC165InterfacesSupportedUpgradeable { + constructor(bytes4[] memory interfaceIds) payable initializer { + __ERC165InterfacesSupported_init(interfaceIds); + } +} +import "./ERC721EnumerableMockUpgradeable.sol"; + +contract ERC721EnumerableMockUpgradeableWithInit is ERC721EnumerableMockUpgradeable { + constructor(string memory name, string memory symbol) payable initializer { + __ERC721EnumerableMock_init(name, symbol); } } import "./ERC1155ReceiverMockUpgradeable.sol"; @@ -384,158 +402,137 @@ contract ERC1155PausableMockUpgradeableWithInit is ERC1155PausableMockUpgradeabl __ERC1155PausableMock_init(uri); } } -import "./ERC165CheckerMockUpgradeable.sol"; +import "./ERC1155BurnableMockUpgradeable.sol"; -contract ERC165CheckerMockUpgradeableWithInit is ERC165CheckerMockUpgradeable { - constructor() payable initializer { - __ERC165CheckerMock_init(); +contract ERC1155BurnableMockUpgradeableWithInit is ERC1155BurnableMockUpgradeable { + constructor(string memory uri) payable initializer { + __ERC1155BurnableMock_init(uri); } } -import "./ERC165/ERC165InterfacesSupportedUpgradeable.sol"; +import "./wizard/MyGovernor3Upgradeable.sol"; -contract SupportsInterfaceWithLookupMockUpgradeableWithInit is SupportsInterfaceWithLookupMockUpgradeable { - constructor() payable initializer { - __SupportsInterfaceWithLookupMock_init(); +contract MyGovernorUpgradeableWithInit is MyGovernorUpgradeable { + constructor(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock) payable initializer { + __MyGovernor_init(_token, _timelock); } } -import "./ERC165/ERC165InterfacesSupportedUpgradeable.sol"; +import "./wizard/MyGovernor2Upgradeable.sol"; -contract ERC165InterfacesSupportedUpgradeableWithInit is ERC165InterfacesSupportedUpgradeable { - constructor(bytes4[] memory interfaceIds) payable initializer { - __ERC165InterfacesSupported_init(interfaceIds); +contract MyGovernor2UpgradeableWithInit is MyGovernor2Upgradeable { + constructor(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock) payable initializer { + __MyGovernor2_init(_token, _timelock); } } -import "./ERC721EnumerableMockUpgradeable.sol"; +import "./wizard/MyGovernor1Upgradeable.sol"; -contract ERC721EnumerableMockUpgradeableWithInit is ERC721EnumerableMockUpgradeable { - constructor(string memory name, string memory symbol) payable initializer { - __ERC721EnumerableMock_init(name, symbol); +contract MyGovernor1UpgradeableWithInit is MyGovernor1Upgradeable { + constructor(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock) payable initializer { + __MyGovernor1_init(_token, _timelock); } } -import "./ERC721RoyaltyMockUpgradeable.sol"; +import "./GovernorWithParamsMockUpgradeable.sol"; -contract ERC721RoyaltyMockUpgradeableWithInit is ERC721RoyaltyMockUpgradeable { - constructor(string memory name, string memory symbol) payable initializer { - __ERC721RoyaltyMock_init(name, symbol); +contract GovernorWithParamsMockUpgradeableWithInit is GovernorWithParamsMockUpgradeable { + constructor(string memory name_, IVotesUpgradeable token_) payable initializer { + __GovernorWithParamsMock_init(name_, token_); } } -import "../token/ERC777/ERC777Upgradeable.sol"; +import "./GovernorVoteMockUpgradeable.sol"; -contract ERC777UpgradeableWithInit is ERC777Upgradeable { - constructor( - string memory name_, - string memory symbol_, - address[] memory defaultOperators_ - ) payable initializer { - __ERC777_init(name_, symbol_, defaultOperators_); +contract GovernorVoteMocksUpgradeableWithInit is GovernorVoteMocksUpgradeable { + constructor(string memory name_, IVotesUpgradeable token_) payable initializer { + __GovernorVoteMocks_init(name_, token_); } } -import "../token/ERC777/presets/ERC777PresetFixedSupplyUpgradeable.sol"; +import "./GovernorTimelockControlMockUpgradeable.sol"; -contract ERC777PresetFixedSupplyUpgradeableWithInit is ERC777PresetFixedSupplyUpgradeable { +contract GovernorTimelockControlMockUpgradeableWithInit is GovernorTimelockControlMockUpgradeable { constructor( - string memory name, - string memory symbol, - address[] memory defaultOperators, - uint256 initialSupply, - address owner + string memory name_, + IVotesUpgradeable token_, + uint256 votingDelay_, + uint256 votingPeriod_, + TimelockControllerUpgradeable timelock_, + uint256 quorumNumerator_ ) payable initializer { - __ERC777PresetFixedSupply_init(name, symbol, defaultOperators, initialSupply, owner); - } -} -import "./ERC777SenderRecipientMockUpgradeable.sol"; - -contract ERC777SenderRecipientMockUpgradeableWithInit is ERC777SenderRecipientMockUpgradeable { - constructor() payable initializer { - __ERC777SenderRecipientMock_init(); - } -} -import "../utils/introspection/ERC1820ImplementerUpgradeable.sol"; - -contract ERC1820ImplementerUpgradeableWithInit is ERC1820ImplementerUpgradeable { - constructor() payable initializer { - __ERC1820Implementer_init(); - } -} -import "./ERC1820ImplementerMockUpgradeable.sol"; - -contract ERC1820ImplementerMockUpgradeableWithInit is ERC1820ImplementerMockUpgradeable { - constructor() payable initializer { - __ERC1820ImplementerMock_init(); - } -} -import "./Create2ImplUpgradeable.sol"; - -contract Create2ImplUpgradeableWithInit is Create2ImplUpgradeable { - constructor() payable initializer { - __Create2Impl_init(); + __GovernorTimelockControlMock_init(name_, token_, votingDelay_, votingPeriod_, timelock_, quorumNumerator_); } } -import "./ERC777MockUpgradeable.sol"; +import "./GovernorTimelockCompoundMockUpgradeable.sol"; -contract ERC777MockUpgradeableWithInit is ERC777MockUpgradeable { +contract GovernorTimelockCompoundMockUpgradeableWithInit is GovernorTimelockCompoundMockUpgradeable { constructor( - address initialHolder, - uint256 initialBalance, - string memory name, - string memory symbol, - address[] memory defaultOperators + string memory name_, + IVotesUpgradeable token_, + uint256 votingDelay_, + uint256 votingPeriod_, + ICompoundTimelockUpgradeable timelock_, + uint256 quorumNumerator_ ) payable initializer { - __ERC777Mock_init(initialHolder, initialBalance, name, symbol, defaultOperators); + __GovernorTimelockCompoundMock_init(name_, token_, votingDelay_, votingPeriod_, timelock_, quorumNumerator_); } } -import "./ERC3156FlashBorrowerMockUpgradeable.sol"; +import "./GovernorCompatibilityBravoMockUpgradeable.sol"; -contract ERC3156FlashBorrowerMockUpgradeableWithInit is ERC3156FlashBorrowerMockUpgradeable { - constructor(bool enableReturn, bool enableApprove) payable initializer { - __ERC3156FlashBorrowerMock_init(enableReturn, enableApprove); +contract GovernorCompatibilityBravoMockUpgradeableWithInit is GovernorCompatibilityBravoMockUpgradeable { + constructor( + string memory name_, + ERC20VotesCompUpgradeable token_, + uint256 votingDelay_, + uint256 votingPeriod_, + uint256 proposalThreshold_, + ICompoundTimelockUpgradeable timelock_ + ) payable initializer { + __GovernorCompatibilityBravoMock_init(name_, token_, votingDelay_, votingPeriod_, proposalThreshold_, timelock_); } } -import "./ERC20FlashMintMockUpgradeable.sol"; +import "./GovernorCompMockUpgradeable.sol"; -contract ERC20FlashMintMockUpgradeableWithInit is ERC20FlashMintMockUpgradeable { - constructor( - string memory name, - string memory symbol, - address initialAccount, - uint256 initialBalance - ) payable initializer { - __ERC20FlashMintMock_init(name, symbol, initialAccount, initialBalance); +contract GovernorCompMockUpgradeableWithInit is GovernorCompMockUpgradeable { + constructor(string memory name_, ERC20VotesCompUpgradeable token_) payable initializer { + __GovernorCompMock_init(name_, token_); } } -import "./ERC1155BurnableMockUpgradeable.sol"; +import "./ERC20VotesCompMockUpgradeable.sol"; -contract ERC1155BurnableMockUpgradeableWithInit is ERC1155BurnableMockUpgradeable { - constructor(string memory uri) payable initializer { - __ERC1155BurnableMock_init(uri); +contract ERC20VotesCompMockUpgradeableWithInit is ERC20VotesCompMockUpgradeable { + constructor(string memory name, string memory symbol) payable initializer { + __ERC20VotesCompMock_init(name, symbol); } } -import "../token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; +import "./SafeCastMockUpgradeable.sol"; -contract ERC1155HolderUpgradeableWithInit is ERC1155HolderUpgradeable { +contract SafeCastMockUpgradeableWithInit is SafeCastMockUpgradeable { constructor() payable initializer { - __ERC1155Holder_init(); + __SafeCastMock_init(); } } -import "./ERC165StorageMockUpgradeable.sol"; +import "./CheckpointsImplUpgradeable.sol"; -contract ERC165StorageMockUpgradeableWithInit is ERC165StorageMockUpgradeable { +contract CheckpointsImplUpgradeableWithInit is CheckpointsImplUpgradeable { constructor() payable initializer { - __ERC165StorageMock_init(); + __CheckpointsImpl_init(); } } -import "./ERC165MockUpgradeable.sol"; +import "./DoubleEndedQueueMockUpgradeable.sol"; -contract ERC165MockUpgradeableWithInit is ERC165MockUpgradeable { +contract Bytes32DequeMockUpgradeableWithInit is Bytes32DequeMockUpgradeable { constructor() payable initializer { - __ERC165Mock_init(); + __Bytes32DequeMock_init(); } } -import "./ERC20VotesCompMockUpgradeable.sol"; +import "./GovernorPreventLateQuorumMockUpgradeable.sol"; -contract ERC20VotesCompMockUpgradeableWithInit is ERC20VotesCompMockUpgradeable { - constructor(string memory name, string memory symbol) payable initializer { - __ERC20VotesCompMock_init(name, symbol); +contract GovernorPreventLateQuorumMockUpgradeableWithInit is GovernorPreventLateQuorumMockUpgradeable { + constructor( + string memory name_, + IVotesUpgradeable token_, + uint256 votingDelay_, + uint256 votingPeriod_, + uint256 quorum_, + uint64 voteExtension_ + ) payable initializer { + __GovernorPreventLateQuorumMock_init(name_, token_, votingDelay_, votingPeriod_, quorum_, voteExtension_); } } import "./GovernorMockUpgradeable.sol"; @@ -565,13 +562,6 @@ contract TimersBlockNumberImplUpgradeableWithInit is TimersBlockNumberImplUpgrad __TimersBlockNumberImpl_init(); } } -import "./DoubleEndedQueueMockUpgradeable.sol"; - -contract Bytes32DequeMockUpgradeableWithInit is Bytes32DequeMockUpgradeable { - constructor() payable initializer { - __Bytes32DequeMock_init(); - } -} import "../token/ERC721/utils/ERC721HolderUpgradeable.sol"; contract ERC721HolderUpgradeableWithInit is ERC721HolderUpgradeable { @@ -586,64 +576,44 @@ contract ERC721ReceiverMockUpgradeableWithInit is ERC721ReceiverMockUpgradeable __ERC721ReceiverMock_init(retval, error); } } -import "../finance/VestingWalletUpgradeable.sol"; +import "../token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; -contract VestingWalletUpgradeableWithInit is VestingWalletUpgradeable { - constructor( - address beneficiaryAddress, - uint64 startTimestamp, - uint64 durationSeconds - ) payable initializer { - __VestingWallet_init(beneficiaryAddress, startTimestamp, durationSeconds); +contract ERC1155HolderUpgradeableWithInit is ERC1155HolderUpgradeable { + constructor() payable initializer { + __ERC1155Holder_init(); } } -import "./ERC20TokenizedVaultMockUpgradeable.sol"; +import "./ERC721RoyaltyMockUpgradeable.sol"; -contract ERC20TokenizedVaultMockUpgradeableWithInit is ERC20TokenizedVaultMockUpgradeable { - constructor( - IERC20MetadataUpgradeable asset, - string memory name, - string memory symbol - ) payable initializer { - __ERC20TokenizedVaultMock_init(asset, name, symbol); +contract ERC721RoyaltyMockUpgradeableWithInit is ERC721RoyaltyMockUpgradeable { + constructor(string memory name, string memory symbol) payable initializer { + __ERC721RoyaltyMock_init(name, symbol); } } -import "./ERC20PausableMockUpgradeable.sol"; +import "./ERC165StorageMockUpgradeable.sol"; -contract ERC20PausableMockUpgradeableWithInit is ERC20PausableMockUpgradeable { - constructor( - string memory name, - string memory symbol, - address initialAccount, - uint256 initialBalance - ) payable initializer { - __ERC20PausableMock_init(name, symbol, initialAccount, initialBalance); +contract ERC165StorageMockUpgradeableWithInit is ERC165StorageMockUpgradeable { + constructor() payable initializer { + __ERC165StorageMock_init(); } } -import "./ERC20MockUpgradeable.sol"; +import "./ERC165MockUpgradeable.sol"; -contract ERC20MockUpgradeableWithInit is ERC20MockUpgradeable { +contract ERC165MockUpgradeableWithInit is ERC165MockUpgradeable { + constructor() payable initializer { + __ERC165Mock_init(); + } +} +import "./ERC20FlashMintMockUpgradeable.sol"; + +contract ERC20FlashMintMockUpgradeableWithInit is ERC20FlashMintMockUpgradeable { constructor( string memory name, string memory symbol, address initialAccount, uint256 initialBalance ) payable initializer { - __ERC20Mock_init(name, symbol, initialAccount, initialBalance); - } -} -import "./MulticallTokenMockUpgradeable.sol"; - -contract MulticallTokenMockUpgradeableWithInit is MulticallTokenMockUpgradeable { - constructor(uint256 initialBalance) payable initializer { - __MulticallTokenMock_init(initialBalance); - } -} -import "./MulticallTestUpgradeable.sol"; - -contract MulticallTestUpgradeableWithInit is MulticallTestUpgradeable { - constructor() payable initializer { - __MulticallTest_init(); + __ERC20FlashMintMock_init(name, symbol, initialAccount, initialBalance); } } import "./ERC20DecimalsMockUpgradeable.sol"; @@ -692,15 +662,45 @@ contract ERC20BurnableMockUpgradeableWithInit is ERC20BurnableMockUpgradeable { __ERC20BurnableMock_init(name, symbol, initialAccount, initialBalance); } } -import "./ERC20WrapperMockUpgradeable.sol"; +import "./ERC20SnapshotMockUpgradeable.sol"; -contract ERC20WrapperMockUpgradeableWithInit is ERC20WrapperMockUpgradeable { +contract ERC20SnapshotMockUpgradeableWithInit is ERC20SnapshotMockUpgradeable { constructor( - IERC20Upgradeable _underlyingToken, + string memory name, + string memory symbol, + address initialAccount, + uint256 initialBalance + ) payable initializer { + __ERC20SnapshotMock_init(name, symbol, initialAccount, initialBalance); + } +} +import "./ArraysImplUpgradeable.sol"; + +contract ArraysImplUpgradeableWithInit is ArraysImplUpgradeable { + constructor(uint256[] memory array) payable initializer { + __ArraysImpl_init(array); + } +} +import "../finance/VestingWalletUpgradeable.sol"; + +contract VestingWalletUpgradeableWithInit is VestingWalletUpgradeable { + constructor( + address beneficiaryAddress, + uint64 startTimestamp, + uint64 durationSeconds + ) payable initializer { + __VestingWallet_init(beneficiaryAddress, startTimestamp, durationSeconds); + } +} +import "./ERC4626MockUpgradeable.sol"; + +contract ERC4626MockUpgradeableWithInit is ERC4626MockUpgradeable { + constructor( + IERC20MetadataUpgradeable asset, string memory name, string memory symbol ) payable initializer { - __ERC20WrapperMock_init(_underlyingToken, name, symbol); + __ERC4626Mock_init(asset, name, symbol); } } import "../finance/PaymentSplitterUpgradeable.sol"; diff --git a/contracts/package.json b/contracts/package.json index dcfbc4ce2..bab5013f6 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,7 +1,7 @@ { "name": "@openzeppelin/contracts-upgradeable", "description": "Secure Smart Contract library for Solidity", - "version": "4.7.0-rc.0", + "version": "4.7.0", "files": [ "**/*.sol", "/build/contracts/*.json", diff --git a/contracts/proxy/ClonesUpgradeable.sol b/contracts/proxy/ClonesUpgradeable.sol index e6724b471..f6a67c769 100644 --- a/contracts/proxy/ClonesUpgradeable.sol +++ b/contracts/proxy/ClonesUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (proxy/Clones.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (proxy/Clones.sol) pragma solidity ^0.8.0; diff --git a/contracts/proxy/utils/Initializable.sol b/contracts/proxy/utils/Initializable.sol index c58638152..3aa7535da 100644 --- a/contracts/proxy/utils/Initializable.sol +++ b/contracts/proxy/utils/Initializable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (proxy/utils/Initializable.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; diff --git a/contracts/security/PausableUpgradeable.sol b/contracts/security/PausableUpgradeable.sol index 79704552f..445648c13 100644 --- a/contracts/security/PausableUpgradeable.sol +++ b/contracts/security/PausableUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (security/Pausable.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; diff --git a/contracts/security/PullPaymentUpgradeable.sol b/contracts/security/PullPaymentUpgradeable.sol index 53cc0755f..51322092b 100644 --- a/contracts/security/PullPaymentUpgradeable.sol +++ b/contracts/security/PullPaymentUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (security/PullPayment.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (security/PullPayment.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC1155/ERC1155Upgradeable.sol b/contracts/token/ERC1155/ERC1155Upgradeable.sol index 206cad6d1..15698118d 100644 --- a/contracts/token/ERC1155/ERC1155Upgradeable.sol +++ b/contracts/token/ERC1155/ERC1155Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC1155/ERC1155.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/ERC1155.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC1155/IERC1155Upgradeable.sol b/contracts/token/ERC1155/IERC1155Upgradeable.sol index f2a8132ca..817fb5262 100644 --- a/contracts/token/ERC1155/IERC1155Upgradeable.sol +++ b/contracts/token/ERC1155/IERC1155Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC1155/IERC1155.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol b/contracts/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol index 3f81057b3..1321eb3a0 100644 --- a/contracts/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol +++ b/contracts/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC1155/extensions/ERC1155Burnable.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/extensions/ERC1155Burnable.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC20/ERC20Upgradeable.sol b/contracts/token/ERC20/ERC20Upgradeable.sol index 4362f2a03..f544f0a51 100644 --- a/contracts/token/ERC20/ERC20Upgradeable.sol +++ b/contracts/token/ERC20/ERC20Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC20/ERC20.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC20/README.adoc b/contracts/token/ERC20/README.adoc index dd1845f07..ae2ce3644 100644 --- a/contracts/token/ERC20/README.adoc +++ b/contracts/token/ERC20/README.adoc @@ -24,7 +24,7 @@ Additionally there are multiple custom extensions, including: * {ERC20Votes}: support for voting and vote delegation. * {ERC20VotesComp}: support for voting and vote delegation (compatible with Compound's token, with uint96 restrictions). * {ERC20Wrapper}: wrapper to create an ERC20 backed by another ERC20, with deposit and withdraw methods. Useful in conjunction with {ERC20Votes}. -* {ERC20TokenizedVault}: tokenized vault that manages shares (represented as ERC20) that are backed by assets (another ERC20). +* {ERC4626}: tokenized vault that manages shares (represented as ERC20) that are backed by assets (another ERC20). Finally, there are some utilities to interact with ERC20 contracts in various ways. @@ -63,7 +63,7 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel {{ERC20FlashMint}} -{{ERC20TokenizedVault}} +{{ERC4626}} == Draft EIPs diff --git a/contracts/token/ERC20/extensions/ERC20FlashMintUpgradeable.sol b/contracts/token/ERC20/extensions/ERC20FlashMintUpgradeable.sol index 53f61776c..13658f879 100644 --- a/contracts/token/ERC20/extensions/ERC20FlashMintUpgradeable.sol +++ b/contracts/token/ERC20/extensions/ERC20FlashMintUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC20/extensions/ERC20FlashMint.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/extensions/ERC20FlashMint.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol b/contracts/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol index e2c7b6546..657ab2e18 100644 --- a/contracts/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol +++ b/contracts/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC20/extensions/ERC20Snapshot.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/extensions/ERC20Snapshot.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC20/extensions/ERC20TokenizedVaultUpgradeable.sol b/contracts/token/ERC20/extensions/ERC4626Upgradeable.sol similarity index 76% rename from contracts/token/ERC20/extensions/ERC20TokenizedVaultUpgradeable.sol rename to contracts/token/ERC20/extensions/ERC4626Upgradeable.sol index 7cd61e513..5f4e9fbbc 100644 --- a/contracts/token/ERC20/extensions/ERC20TokenizedVaultUpgradeable.sol +++ b/contracts/token/ERC20/extensions/ERC4626Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC20/extensions/ERC20TokenizedVault.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/extensions/ERC4626.sol) pragma solidity ^0.8.0; @@ -18,9 +18,13 @@ import "../../../proxy/utils/Initializable.sol"; * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this * contract and not the "assets" token which is an independent contract. * + * CAUTION: Deposits and withdrawals may incur unexpected slippage. Users should verify that the amount received of + * shares or assets is as expected. EOAs should operate through a wrapper that performs these checks such as + * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router]. + * * _Available since v4.7._ */ -abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradeable, IERC4626Upgradeable { +abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626Upgradeable { using MathUpgradeable for uint256; IERC20MetadataUpgradeable private _asset; @@ -28,77 +32,77 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea /** * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777). */ - function __ERC20TokenizedVault_init(IERC20MetadataUpgradeable asset_) internal onlyInitializing { - __ERC20TokenizedVault_init_unchained(asset_); + function __ERC4626_init(IERC20MetadataUpgradeable asset_) internal onlyInitializing { + __ERC4626_init_unchained(asset_); } - function __ERC20TokenizedVault_init_unchained(IERC20MetadataUpgradeable asset_) internal onlyInitializing { + function __ERC4626_init_unchained(IERC20MetadataUpgradeable asset_) internal onlyInitializing { _asset = asset_; } - /** @dev See {IERC4262-asset} */ + /** @dev See {IERC4262-asset}. */ function asset() public view virtual override returns (address) { return address(_asset); } - /** @dev See {IERC4262-totalAssets} */ + /** @dev See {IERC4262-totalAssets}. */ function totalAssets() public view virtual override returns (uint256) { return _asset.balanceOf(address(this)); } - /** @dev See {IERC4262-convertToShares} */ + /** @dev See {IERC4262-convertToShares}. */ function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) { return _convertToShares(assets, MathUpgradeable.Rounding.Down); } - /** @dev See {IERC4262-convertToAssets} */ + /** @dev See {IERC4262-convertToAssets}. */ function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) { return _convertToAssets(shares, MathUpgradeable.Rounding.Down); } - /** @dev See {IERC4262-maxDeposit} */ + /** @dev See {IERC4262-maxDeposit}. */ function maxDeposit(address) public view virtual override returns (uint256) { return _isVaultCollateralized() ? type(uint256).max : 0; } - /** @dev See {IERC4262-maxMint} */ + /** @dev See {IERC4262-maxMint}. */ function maxMint(address) public view virtual override returns (uint256) { return type(uint256).max; } - /** @dev See {IERC4262-maxWithdraw} */ + /** @dev See {IERC4262-maxWithdraw}. */ function maxWithdraw(address owner) public view virtual override returns (uint256) { return _convertToAssets(balanceOf(owner), MathUpgradeable.Rounding.Down); } - /** @dev See {IERC4262-maxRedeem} */ + /** @dev See {IERC4262-maxRedeem}. */ function maxRedeem(address owner) public view virtual override returns (uint256) { return balanceOf(owner); } - /** @dev See {IERC4262-previewDeposit} */ + /** @dev See {IERC4262-previewDeposit}. */ function previewDeposit(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Down); } - /** @dev See {IERC4262-previewMint} */ + /** @dev See {IERC4262-previewMint}. */ function previewMint(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Up); } - /** @dev See {IERC4262-previewWithdraw} */ + /** @dev See {IERC4262-previewWithdraw}. */ function previewWithdraw(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Up); } - /** @dev See {IERC4262-previewRedeem} */ + /** @dev See {IERC4262-previewRedeem}. */ function previewRedeem(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Down); } - /** @dev See {IERC4262-deposit} */ + /** @dev See {IERC4262-deposit}. */ function deposit(uint256 assets, address receiver) public virtual override returns (uint256) { - require(assets <= maxDeposit(receiver), "ERC20TokenizedVault: deposit more than max"); + require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max"); uint256 shares = previewDeposit(assets); _deposit(_msgSender(), receiver, assets, shares); @@ -106,9 +110,9 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea return shares; } - /** @dev See {IERC4262-mint} */ + /** @dev See {IERC4262-mint}. */ function mint(uint256 shares, address receiver) public virtual override returns (uint256) { - require(shares <= maxMint(receiver), "ERC20TokenizedVault: mint more than max"); + require(shares <= maxMint(receiver), "ERC4626: mint more than max"); uint256 assets = previewMint(shares); _deposit(_msgSender(), receiver, assets, shares); @@ -116,13 +120,13 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea return assets; } - /** @dev See {IERC4262-withdraw} */ + /** @dev See {IERC4262-withdraw}. */ function withdraw( uint256 assets, address receiver, address owner ) public virtual override returns (uint256) { - require(assets <= maxWithdraw(owner), "ERC20TokenizedVault: withdraw more than max"); + require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max"); uint256 shares = previewWithdraw(assets); _withdraw(_msgSender(), receiver, owner, assets, shares); @@ -130,13 +134,13 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea return shares; } - /** @dev See {IERC4262-redeem} */ + /** @dev See {IERC4262-redeem}. */ function redeem( uint256 shares, address receiver, address owner ) public virtual override returns (uint256) { - require(shares <= maxRedeem(owner), "ERC20TokenizedVault: redeem more than max"); + require(shares <= maxRedeem(owner), "ERC4626: redeem more than max"); uint256 assets = previewRedeem(shares); _withdraw(_msgSender(), receiver, owner, assets, shares); @@ -145,7 +149,7 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea } /** - * @dev Internal convertion function (from assets to shares) with support for rounding direction + * @dev Internal conversion function (from assets to shares) with support for rounding direction. * * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset * would represent an infinite amout of shares. @@ -159,7 +163,7 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea } /** - * @dev Internal convertion function (from shares to assets) with support for rounding direction + * @dev Internal conversion function (from shares to assets) with support for rounding direction. */ function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256 assets) { uint256 supply = totalSupply(); @@ -170,14 +174,14 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea } /** - * @dev Deposit/mint common workflow + * @dev Deposit/mint common workflow. */ function _deposit( address caller, address receiver, uint256 assets, uint256 shares - ) private { + ) internal virtual { // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer, // calls the vault, which is assumed not malicious. @@ -192,7 +196,7 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea } /** - * @dev Withdraw/redeem common workflow + * @dev Withdraw/redeem common workflow. */ function _withdraw( address caller, @@ -200,12 +204,12 @@ abstract contract ERC20TokenizedVaultUpgradeable is Initializable, ERC20Upgradea address owner, uint256 assets, uint256 shares - ) private { + ) internal virtual { if (caller != owner) { _spendAllowance(owner, caller, shares); } - // If _asset is ERC777, `transfer` can trigger trigger a reentrancy AFTER the transfer happens through the + // If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer, // calls the vault, which is assumed not malicious. // diff --git a/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol b/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol index 93f99cc44..65d2fc1a7 100644 --- a/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol +++ b/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC20/utils/SafeERC20.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC721/ERC721Upgradeable.sol b/contracts/token/ERC721/ERC721Upgradeable.sol index ccf970bf2..f06a3931a 100644 --- a/contracts/token/ERC721/ERC721Upgradeable.sol +++ b/contracts/token/ERC721/ERC721Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC721/ERC721.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC721/IERC721Upgradeable.sol b/contracts/token/ERC721/IERC721Upgradeable.sol index c43b71afb..2c34f768d 100644 --- a/contracts/token/ERC721/IERC721Upgradeable.sol +++ b/contracts/token/ERC721/IERC721Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC721/IERC721.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC721/extensions/ERC721BurnableUpgradeable.sol b/contracts/token/ERC721/extensions/ERC721BurnableUpgradeable.sol index 5da08f5bc..b857f05fd 100644 --- a/contracts/token/ERC721/extensions/ERC721BurnableUpgradeable.sol +++ b/contracts/token/ERC721/extensions/ERC721BurnableUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC721/extensions/ERC721Burnable.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/extensions/ERC721Burnable.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol b/contracts/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol index 40d6dac37..5f349d25a 100644 --- a/contracts/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol +++ b/contracts/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC721/extensions/ERC721URIStorage.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/extensions/ERC721URIStorage.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/ERC777/ERC777Upgradeable.sol b/contracts/token/ERC777/ERC777Upgradeable.sol index 73a007746..c01bfa5e0 100644 --- a/contracts/token/ERC777/ERC777Upgradeable.sol +++ b/contracts/token/ERC777/ERC777Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/ERC777/ERC777.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC777/ERC777.sol) pragma solidity ^0.8.0; diff --git a/contracts/token/common/ERC2981Upgradeable.sol b/contracts/token/common/ERC2981Upgradeable.sol index 212d84f73..12ef99032 100644 --- a/contracts/token/common/ERC2981Upgradeable.sol +++ b/contracts/token/common/ERC2981Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (token/common/ERC2981.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (token/common/ERC2981.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/AddressUpgradeable.sol b/contracts/utils/AddressUpgradeable.sol index e7b565dfa..124513390 100644 --- a/contracts/utils/AddressUpgradeable.sol +++ b/contracts/utils/AddressUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/Address.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; diff --git a/contracts/utils/Base64Upgradeable.sol b/contracts/utils/Base64Upgradeable.sol index b2e3cd759..1ca0a0bfb 100644 --- a/contracts/utils/Base64Upgradeable.sol +++ b/contracts/utils/Base64Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/Base64.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/Base64.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/Create2Upgradeable.sol b/contracts/utils/Create2Upgradeable.sol index b1ce51887..08e95df67 100644 --- a/contracts/utils/Create2Upgradeable.sol +++ b/contracts/utils/Create2Upgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/Create2.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/Create2.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/StorageSlotUpgradeable.sol b/contracts/utils/StorageSlotUpgradeable.sol index 1b9cc7ada..d95ae3c37 100644 --- a/contracts/utils/StorageSlotUpgradeable.sol +++ b/contracts/utils/StorageSlotUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/StorageSlot.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/StringsUpgradeable.sol b/contracts/utils/StringsUpgradeable.sol index fc9659a52..6626b56fd 100644 --- a/contracts/utils/StringsUpgradeable.sol +++ b/contracts/utils/StringsUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/Strings.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/cryptography/ECDSAUpgradeable.sol b/contracts/utils/cryptography/ECDSAUpgradeable.sol index 4ba565010..045523640 100644 --- a/contracts/utils/cryptography/ECDSAUpgradeable.sol +++ b/contracts/utils/cryptography/ECDSAUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/cryptography/ECDSA.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/cryptography/MerkleProofUpgradeable.sol b/contracts/utils/cryptography/MerkleProofUpgradeable.sol index e543177fe..57782a7a0 100644 --- a/contracts/utils/cryptography/MerkleProofUpgradeable.sol +++ b/contracts/utils/cryptography/MerkleProofUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/cryptography/MerkleProof.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/MerkleProof.sol) pragma solidity ^0.8.0; @@ -81,12 +81,26 @@ library MerkleProofUpgradeable { * _Available since v4.7._ */ function multiProofVerify( + bytes32[] memory proof, + bool[] memory proofFlags, + bytes32 root, + bytes32[] memory leaves + ) internal pure returns (bool) { + return processMultiProof(proof, proofFlags, leaves) == root; + } + + /** + * @dev Calldata version of {multiProofVerify} + * + * _Available since v4.7._ + */ + function multiProofVerifyCalldata( bytes32[] calldata proof, bool[] calldata proofFlags, bytes32 root, - bytes32[] calldata leaves + bytes32[] memory leaves ) internal pure returns (bool) { - return processMultiProof(proof, proofFlags, leaves) == root; + return processMultiProofCalldata(proof, proofFlags, leaves) == root; } /** @@ -97,9 +111,55 @@ library MerkleProofUpgradeable { * _Available since v4.7._ */ function processMultiProof( + bytes32[] memory proof, + bool[] memory proofFlags, + bytes32[] memory leaves + ) internal pure returns (bytes32 merkleRoot) { + // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by + // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the + // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of + // the merkle tree. + uint256 leavesLen = leaves.length; + uint256 totalHashes = proofFlags.length; + + // Check proof validity. + require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); + + // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using + // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop". + bytes32[] memory hashes = new bytes32[](totalHashes); + uint256 leafPos = 0; + uint256 hashPos = 0; + uint256 proofPos = 0; + // At each step, we compute the next hash using two values: + // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we + // get the next hash. + // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the + // `proof` array. + for (uint256 i = 0; i < totalHashes; i++) { + bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; + bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; + hashes[i] = _hashPair(a, b); + } + + if (totalHashes > 0) { + return hashes[totalHashes - 1]; + } else if (leavesLen > 0) { + return leaves[0]; + } else { + return proof[0]; + } + } + + /** + * @dev Calldata version of {processMultiProof} + * + * _Available since v4.7._ + */ + function processMultiProofCalldata( bytes32[] calldata proof, bool[] calldata proofFlags, - bytes32[] calldata leaves + bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the diff --git a/contracts/utils/escrow/EscrowUpgradeable.sol b/contracts/utils/escrow/EscrowUpgradeable.sol index b37a3df38..41740376f 100644 --- a/contracts/utils/escrow/EscrowUpgradeable.sol +++ b/contracts/utils/escrow/EscrowUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/escrow/Escrow.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/escrow/Escrow.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/math/MathUpgradeable.sol b/contracts/utils/math/MathUpgradeable.sol index e95fc4568..9a0e28225 100644 --- a/contracts/utils/math/MathUpgradeable.sol +++ b/contracts/utils/math/MathUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/math/Math.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/math/SafeCastUpgradeable.sol b/contracts/utils/math/SafeCastUpgradeable.sol index d201f876e..ddfefa569 100644 --- a/contracts/utils/math/SafeCastUpgradeable.sol +++ b/contracts/utils/math/SafeCastUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/math/SafeCast.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/SafeCast.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/structs/EnumerableMapUpgradeable.sol b/contracts/utils/structs/EnumerableMapUpgradeable.sol index 6fa13b80b..0c59c8dae 100644 --- a/contracts/utils/structs/EnumerableMapUpgradeable.sol +++ b/contracts/utils/structs/EnumerableMapUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/structs/EnumerableMap.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableMap.sol) pragma solidity ^0.8.0; diff --git a/contracts/utils/structs/EnumerableSetUpgradeable.sol b/contracts/utils/structs/EnumerableSetUpgradeable.sol index 8927c2c83..e9dc8cc57 100644 --- a/contracts/utils/structs/EnumerableSetUpgradeable.sol +++ b/contracts/utils/structs/EnumerableSetUpgradeable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.7.0-rc.0) (utils/structs/EnumerableSet.sol) +// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol) pragma solidity ^0.8.0; diff --git a/package-lock.json b/package-lock.json index 1c9387bc0..c0267918e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "openzeppelin-solidity", - "version": "4.7.0-rc.0", + "version": "4.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "openzeppelin-solidity", - "version": "4.6.0", + "version": "4.7.0", "license": "MIT", "bin": { "openzeppelin-contracts-migrate-imports": "scripts/migrate-imports.js" diff --git a/package.json b/package.json index e08814ea9..03ea17129 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": true, "name": "openzeppelin-solidity", "description": "Secure Smart Contract library for Solidity", - "version": "4.7.0-rc.0", + "version": "4.7.0", "files": [ "/contracts/**/*.sol", "/build/contracts/*.json", diff --git a/scripts/checks/generation.sh b/scripts/checks/generation.sh index 165c35a06..00d609f94 100755 --- a/scripts/checks/generation.sh +++ b/scripts/checks/generation.sh @@ -3,4 +3,4 @@ set -euo pipefail npm run generate -git diff --quiet --exit-code +git diff -R --exit-code diff --git a/scripts/generate/run.js b/scripts/generate/run.js index 5ebb1b37a..0072653d0 100755 --- a/scripts/generate/run.js +++ b/scripts/generate/run.js @@ -7,7 +7,7 @@ function getVersion (path) { try { return fs .readFileSync(path, 'utf8') - .match(/\/\/ OpenZeppelin Contracts \(last updated v\d+\.\d+\.\d+\)/)[0]; + .match(/\/\/ OpenZeppelin Contracts \(last updated v[^)]+\)/)[0]; } catch (err) { return null; } diff --git a/test/token/ERC20/extensions/ERC20TokenizedVault.test.js b/test/token/ERC20/extensions/ERC4626.test.js similarity index 98% rename from test/token/ERC20/extensions/ERC20TokenizedVault.test.js rename to test/token/ERC20/extensions/ERC4626.test.js index 0c20570d7..63b995f40 100644 --- a/test/token/ERC20/extensions/ERC20TokenizedVault.test.js +++ b/test/token/ERC20/extensions/ERC4626.test.js @@ -2,12 +2,12 @@ const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test const { expect } = require('chai'); const ERC20DecimalsMock = artifacts.require('ERC20DecimalsMock'); -const ERC20TokenizedVaultMock = artifacts.require('ERC20TokenizedVaultMock'); +const ERC4626Mock = artifacts.require('ERC4626Mock'); const parseToken = (token) => (new BN(token)).mul(new BN('1000000000000')); const parseShare = (share) => (new BN(share)).mul(new BN('1000000000000000000')); -contract('ERC20TokenizedVault', function (accounts) { +contract('ERC4626', function (accounts) { const [ holder, recipient, spender, other, user1, user2 ] = accounts; const name = 'My Token'; @@ -15,7 +15,7 @@ contract('ERC20TokenizedVault', function (accounts) { beforeEach(async function () { this.token = await ERC20DecimalsMock.new(name, symbol, 12); - this.vault = await ERC20TokenizedVaultMock.new(this.token.address, name + ' Vault', symbol + 'V'); + this.vault = await ERC4626Mock.new(this.token.address, name + ' Vault', symbol + 'V'); await this.token.mint(holder, web3.utils.toWei('100')); await this.token.approve(this.vault.address, constants.MAX_UINT256, { from: holder }); @@ -227,7 +227,7 @@ contract('ERC20TokenizedVault', function (accounts) { await expectRevert.unspecified(this.vault.previewDeposit(parseToken(1))); await expectRevert( this.vault.deposit(parseToken(1), recipient, { from: holder }), - 'ERC20TokenizedVault: deposit more than max', + 'ERC4626: deposit more than max', ); }); @@ -400,7 +400,7 @@ contract('ERC20TokenizedVault', function (accounts) { it('multiple mint, deposit, redeem & withdrawal', async function () { // test designed with both asset using similar decimals this.token = await ERC20DecimalsMock.new(name, symbol, 18); - this.vault = await ERC20TokenizedVaultMock.new(this.token.address, name + ' Vault', symbol + 'V'); + this.vault = await ERC4626Mock.new(this.token.address, name + ' Vault', symbol + 'V'); await this.token.mint(user1, 4000); await this.token.mint(user2, 7001); diff --git a/test/utils/cryptography/MerkleProof.test.js b/test/utils/cryptography/MerkleProof.test.js index 1bb3de7f1..2d4aacdac 100644 --- a/test/utils/cryptography/MerkleProof.test.js +++ b/test/utils/cryptography/MerkleProof.test.js @@ -79,6 +79,7 @@ contract('MerkleProof', function (accounts) { const proofFlags = merkleTree.getProofFlags(proofLeaves, proof); expect(await this.merkleProof.multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true); + expect(await this.merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true); }); it('returns false for an invalid Merkle multi proof', async function () { @@ -91,7 +92,10 @@ contract('MerkleProof', function (accounts) { const badProof = badMerkleTree.getMultiProof(badProofLeaves); const badProofFlags = badMerkleTree.getProofFlags(badProofLeaves, badProof); - expect(await this.merkleProof.multiProofVerify(badProof, badProofFlags, root, badProofLeaves)).to.equal(false); + expect(await this.merkleProof.multiProofVerify(badProof, badProofFlags, root, badProofLeaves)) + .to.equal(false); + expect(await this.merkleProof.multiProofVerifyCalldata(badProof, badProofFlags, root, badProofLeaves)) + .to.equal(false); }); it('revert with invalid multi proof #1', async function () { @@ -111,6 +115,15 @@ contract('MerkleProof', function (accounts) { ), 'MerkleProof: invalid multiproof', ); + await expectRevert( + this.merkleProof.multiProofVerifyCalldata( + [ leaves[1], fill, merkleTree.layers[1][1] ], + [ false, false, false ], + root, + [ leaves[0], badLeaf ], // A, E + ), + 'MerkleProof: invalid multiproof', + ); }); it('revert with invalid multi proof #2', async function () { @@ -130,6 +143,15 @@ contract('MerkleProof', function (accounts) { ), 'reverted with panic code 0x32', ); + await expectRevert( + this.merkleProof.multiProofVerifyCalldata( + [ leaves[1], fill, merkleTree.layers[1][1] ], + [ false, false, false, false ], + root, + [ badLeaf, leaves[0] ], // A, E + ), + 'reverted with panic code 0x32', + ); }); it('limit case: works for tree containing a single leaf', async function () { @@ -142,6 +164,7 @@ contract('MerkleProof', function (accounts) { const proofFlags = merkleTree.getProofFlags(proofLeaves, proof); expect(await this.merkleProof.multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true); + expect(await this.merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true); }); it('limit case: can prove empty leaves', async function () { @@ -150,6 +173,7 @@ contract('MerkleProof', function (accounts) { const root = merkleTree.getRoot(); expect(await this.merkleProof.multiProofVerify([ root ], [], root, [])).to.equal(true); + expect(await this.merkleProof.multiProofVerifyCalldata([ root ], [], root, [])).to.equal(true); }); }); });