-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into token-test-improvements
- Loading branch information
Showing
14 changed files
with
550 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.5; | ||
|
||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2018 Murray Software, LLC. | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
/// @notice Implementation of [EIP-1167] based on [clone-factory] | ||
/// source code. | ||
/// | ||
/// EIP 1167: https://eips.ethereum.org/EIPS/eip-1167 | ||
// Original implementation: https://github.com/optionality/clone-factory | ||
// Modified to use ^0.8.5; instead of ^0.4.23 solidity version. | ||
/* solhint-disable no-inline-assembly */ | ||
abstract contract CloneFactory { | ||
/// @notice Creates EIP-1167 clone of the contract under the provided | ||
/// `target` address. Returns address of the created clone. | ||
/// @dev In specific circumstances, such as the `target` contract destroyed, | ||
/// create opcode may return 0x0 address. The code calling this | ||
/// function should handle this corner case properly. | ||
function createClone(address target) internal returns (address result) { | ||
bytes20 targetBytes = bytes20(target); | ||
assembly { | ||
let clone := mload(0x40) | ||
mstore( | ||
clone, | ||
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000 | ||
) | ||
mstore(add(clone, 0x14), targetBytes) | ||
mstore( | ||
add(clone, 0x28), | ||
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 | ||
) | ||
result := create(0, clone, 0x37) | ||
} | ||
} | ||
|
||
/// @notice Checks if the contract under the `query` address is a EIP-1167 | ||
/// clone of the contract under `target` address. | ||
function isClone(address target, address query) | ||
internal | ||
view | ||
returns (bool result) | ||
{ | ||
bytes20 targetBytes = bytes20(target); | ||
assembly { | ||
let clone := mload(0x40) | ||
mstore( | ||
clone, | ||
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000 | ||
) | ||
mstore(add(clone, 0xa), targetBytes) | ||
mstore( | ||
add(clone, 0x1e), | ||
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 | ||
) | ||
|
||
let other := add(clone, 0x40) | ||
extcodecopy(query, other, 0, 0x2d) | ||
result := and( | ||
eq(mload(clone), mload(other)), | ||
eq(mload(add(clone, 0xd)), mload(add(other, 0xd))) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "../../clone/CloneFactory.sol"; | ||
|
||
contract CloneFactoryStub is CloneFactory { | ||
event CloneCreated(address cloneAddress); | ||
|
||
function createClonePublic(address target) external { | ||
emit CloneCreated(createClone(target)); | ||
} | ||
|
||
function isClonePublic(address target, address query) | ||
external | ||
view | ||
returns (bool) | ||
{ | ||
return isClone(target, query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
contract Cloneable { | ||
uint256 public value; | ||
|
||
function initialize(uint256 _value) external { | ||
value = _value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "../../token/ERC20WithPermit.sol"; | ||
|
||
contract ERC20WithPermitStub is ERC20WithPermit { | ||
event BeforeTokenTransferCalled(address from, address to, uint256 amount); | ||
|
||
constructor(string memory _name, string memory _symbol) | ||
ERC20WithPermit(_name, _symbol) | ||
{} | ||
|
||
function beforeTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) internal override { | ||
emit BeforeTokenTransferCalled(from, to, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "../../token/ERC20WithPermit.sol"; | ||
|
||
contract TestERC20 is ERC20WithPermit { | ||
string public constant NAME = "Test ERC20 Token"; | ||
string public constant SYMBOL = "TT"; | ||
|
||
constructor() ERC20WithPermit(NAME, SYMBOL) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
|
||
contract TestERC721 is ERC721 { | ||
string public constant NAME = "Test ERC721 Token"; | ||
string public constant SYMBOL = "TT"; | ||
|
||
constructor() ERC721(NAME, SYMBOL) {} | ||
|
||
function mint(address to, uint256 tokenId) public { | ||
_mint(to, tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; | ||
|
||
/// @title MisfundRecovery | ||
/// @notice Allows the owner of the token contract extending MisfundRecovery | ||
/// to recover any ERC20 and ERC721 sent mistakenly to the token | ||
/// contract address. | ||
contract MisfundRecovery is Ownable { | ||
using SafeERC20 for IERC20; | ||
|
||
function recoverERC20( | ||
IERC20 token, | ||
address recipient, | ||
uint256 amount | ||
) external onlyOwner { | ||
token.safeTransfer(recipient, amount); | ||
} | ||
|
||
function recoverERC721( | ||
IERC721 token, | ||
address recipient, | ||
uint256 tokenId, | ||
bytes calldata data | ||
) external onlyOwner { | ||
token.safeTransferFrom(address(this), recipient, tokenId, data); | ||
} | ||
} |
Oops, something went wrong.