mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 19:26:33 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC1155/IERC1155Receiver.sol";
|
||||
import "../../utils/introspection/ERC165.sol";
|
||||
|
||||
contract ERC1155ReceiverMock is ERC165, IERC1155Receiver {
|
||||
bytes4 private _recRetval;
|
||||
bool private _recReverts;
|
||||
bytes4 private _batRetval;
|
||||
bool private _batReverts;
|
||||
|
||||
event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas);
|
||||
event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas);
|
||||
|
||||
constructor(bytes4 recRetval, bool recReverts, bytes4 batRetval, bool batReverts) {
|
||||
_recRetval = recRetval;
|
||||
_recReverts = recReverts;
|
||||
_batRetval = batRetval;
|
||||
_batReverts = batReverts;
|
||||
}
|
||||
|
||||
function onERC1155Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 id,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
) external override returns (bytes4) {
|
||||
require(!_recReverts, "ERC1155ReceiverMock: reverting on receive");
|
||||
emit Received(operator, from, id, value, data, gasleft());
|
||||
return _recRetval;
|
||||
}
|
||||
|
||||
function onERC1155BatchReceived(
|
||||
address operator,
|
||||
address from,
|
||||
uint256[] calldata ids,
|
||||
uint256[] calldata values,
|
||||
bytes calldata data
|
||||
) external override returns (bytes4) {
|
||||
require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive");
|
||||
emit BatchReceived(operator, from, ids, values, data, gasleft());
|
||||
return _batRetval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
abstract contract ERC20DecimalsMock is ERC20 {
|
||||
uint8 private immutable _decimals;
|
||||
|
||||
constructor(uint8 decimals_) {
|
||||
_decimals = decimals_;
|
||||
}
|
||||
|
||||
function decimals() public view override returns (uint8) {
|
||||
return _decimals;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract ERC20ExcessDecimalsMock {
|
||||
function decimals() public pure returns (uint256) {
|
||||
return type(uint256).max;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/extensions/ERC20FlashMint.sol";
|
||||
|
||||
abstract contract ERC20FlashMintMock is ERC20FlashMint {
|
||||
uint256 _flashFeeAmount;
|
||||
address _flashFeeReceiverAddress;
|
||||
|
||||
function setFlashFee(uint256 amount) public {
|
||||
_flashFeeAmount = amount;
|
||||
}
|
||||
|
||||
function _flashFee(address, uint256) internal view override returns (uint256) {
|
||||
return _flashFeeAmount;
|
||||
}
|
||||
|
||||
function setFlashFeeReceiver(address receiver) public {
|
||||
_flashFeeReceiverAddress = receiver;
|
||||
}
|
||||
|
||||
function _flashFeeReceiver() internal view override returns (address) {
|
||||
return _flashFeeReceiverAddress;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
// contract that replicate USDT (0xdac17f958d2ee523a2206206994597c13d831ec7) approval beavior
|
||||
abstract contract ERC20ForceApproveMock is ERC20 {
|
||||
function approve(address spender, uint256 amount) public virtual override returns (bool) {
|
||||
require(amount == 0 || allowance(msg.sender, spender) == 0, "USDT approval failure");
|
||||
return super.approve(spender, amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
import "../../utils/Multicall.sol";
|
||||
|
||||
abstract contract ERC20MulticallMock is ERC20, Multicall {}
|
||||
@@ -0,0 +1,28 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
abstract contract ERC20NoReturnMock is ERC20 {
|
||||
function transfer(address to, uint256 amount) public override returns (bool) {
|
||||
super.transfer(to, amount);
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
|
||||
super.transferFrom(from, to, amount);
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
function approve(address spender, uint256 amount) public override returns (bool) {
|
||||
super.approve(spender, amount);
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
import "../../token/ERC20/extensions/draft-ERC20Permit.sol";
|
||||
|
||||
abstract contract ERC20PermitNoRevertMock is ERC20Permit {
|
||||
function permitThatMayRevert(
|
||||
address owner,
|
||||
address spender,
|
||||
uint256 value,
|
||||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) public virtual {
|
||||
super.permit(owner, spender, value, deadline, v, r, s);
|
||||
}
|
||||
|
||||
function permit(
|
||||
address owner,
|
||||
address spender,
|
||||
uint256 value,
|
||||
uint256 deadline,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) public virtual override {
|
||||
try this.permitThatMayRevert(owner, spender, value, deadline, v, r, s) {
|
||||
// do nothing
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/ERC20.sol";
|
||||
|
||||
abstract contract ERC20ReturnFalseMock is ERC20 {
|
||||
function transfer(address, uint256) public pure override returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function transferFrom(address, address, uint256) public pure override returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function approve(address, uint256) public pure override returns (bool) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/extensions/ERC20Permit.sol";
|
||||
import "../../utils/math/Math.sol";
|
||||
import "../../governance/utils/IVotes.sol";
|
||||
import "../../utils/math/SafeCast.sol";
|
||||
import "../../utils/cryptography/ECDSA.sol";
|
||||
|
||||
/**
|
||||
* @dev Copied from the master branch at commit 86de1e8b6c3fa6b4efa4a5435869d2521be0f5f5
|
||||
*/
|
||||
abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
|
||||
struct Checkpoint {
|
||||
uint32 fromBlock;
|
||||
uint224 votes;
|
||||
}
|
||||
|
||||
bytes32 private constant _DELEGATION_TYPEHASH =
|
||||
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
|
||||
|
||||
mapping(address => address) private _delegates;
|
||||
mapping(address => Checkpoint[]) private _checkpoints;
|
||||
Checkpoint[] private _totalSupplyCheckpoints;
|
||||
|
||||
/**
|
||||
* @dev Get the `pos`-th checkpoint for `account`.
|
||||
*/
|
||||
function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) {
|
||||
return _checkpoints[account][pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get number of checkpoints for `account`.
|
||||
*/
|
||||
function numCheckpoints(address account) public view virtual returns (uint32) {
|
||||
return SafeCast.toUint32(_checkpoints[account].length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get the address `account` is currently delegating to.
|
||||
*/
|
||||
function delegates(address account) public view virtual override returns (address) {
|
||||
return _delegates[account];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Gets the current votes balance for `account`
|
||||
*/
|
||||
function getVotes(address account) public view virtual override returns (uint256) {
|
||||
uint256 pos = _checkpoints[account].length;
|
||||
unchecked {
|
||||
return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Retrieve the number of votes for `account` at the end of `blockNumber`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `blockNumber` must have been already mined
|
||||
*/
|
||||
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
|
||||
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
|
||||
return _checkpointsLookup(_checkpoints[account], blockNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.
|
||||
* It is NOT the sum of all the delegated votes!
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `blockNumber` must have been already mined
|
||||
*/
|
||||
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256) {
|
||||
require(blockNumber < block.number, "ERC20Votes: block not yet mined");
|
||||
return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Lookup a value in a list of (sorted) checkpoints.
|
||||
*/
|
||||
function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) {
|
||||
// We run a binary search to look for the earliest checkpoint taken after `blockNumber`.
|
||||
//
|
||||
// Initially we check if the block is recent to narrow the search range.
|
||||
// During the loop, the index of the wanted checkpoint remains in the range [low-1, high).
|
||||
// With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant.
|
||||
// - If the middle checkpoint is after `blockNumber`, we look in [low, mid)
|
||||
// - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)
|
||||
// Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not
|
||||
// out of bounds (in which case we're looking too far in the past and the result is 0).
|
||||
// Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is
|
||||
// past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out
|
||||
// the same.
|
||||
uint256 length = ckpts.length;
|
||||
|
||||
uint256 low = 0;
|
||||
uint256 high = length;
|
||||
|
||||
if (length > 5) {
|
||||
uint256 mid = length - Math.sqrt(length);
|
||||
if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {
|
||||
high = mid;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (low < high) {
|
||||
uint256 mid = Math.average(low, high);
|
||||
if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {
|
||||
high = mid;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
unchecked {
|
||||
return high == 0 ? 0 : _unsafeAccess(ckpts, high - 1).votes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Delegate votes from the sender to `delegatee`.
|
||||
*/
|
||||
function delegate(address delegatee) public virtual override {
|
||||
_delegate(_msgSender(), delegatee);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Delegates votes from signer to `delegatee`
|
||||
*/
|
||||
function delegateBySig(
|
||||
address delegatee,
|
||||
uint256 nonce,
|
||||
uint256 expiry,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) public virtual override {
|
||||
require(block.timestamp <= expiry, "ERC20Votes: signature expired");
|
||||
address signer = ECDSA.recover(
|
||||
_hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
|
||||
v,
|
||||
r,
|
||||
s
|
||||
);
|
||||
require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
|
||||
_delegate(signer, delegatee);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
|
||||
*/
|
||||
function _maxSupply() internal view virtual returns (uint224) {
|
||||
return type(uint224).max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Snapshots the totalSupply after it has been increased.
|
||||
*/
|
||||
function _mint(address account, uint256 amount) internal virtual override {
|
||||
super._mint(account, amount);
|
||||
require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
|
||||
|
||||
_writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Snapshots the totalSupply after it has been decreased.
|
||||
*/
|
||||
function _burn(address account, uint256 amount) internal virtual override {
|
||||
super._burn(account, amount);
|
||||
|
||||
_writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Move voting power when tokens are transferred.
|
||||
*
|
||||
* Emits a {IVotes-DelegateVotesChanged} event.
|
||||
*/
|
||||
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual override {
|
||||
super._afterTokenTransfer(from, to, amount);
|
||||
|
||||
_moveVotingPower(delegates(from), delegates(to), amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Change delegation for `delegator` to `delegatee`.
|
||||
*
|
||||
* Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
|
||||
*/
|
||||
function _delegate(address delegator, address delegatee) internal virtual {
|
||||
address currentDelegate = delegates(delegator);
|
||||
uint256 delegatorBalance = balanceOf(delegator);
|
||||
_delegates[delegator] = delegatee;
|
||||
|
||||
emit DelegateChanged(delegator, currentDelegate, delegatee);
|
||||
|
||||
_moveVotingPower(currentDelegate, delegatee, delegatorBalance);
|
||||
}
|
||||
|
||||
function _moveVotingPower(address src, address dst, uint256 amount) private {
|
||||
if (src != dst && amount > 0) {
|
||||
if (src != address(0)) {
|
||||
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
|
||||
emit DelegateVotesChanged(src, oldWeight, newWeight);
|
||||
}
|
||||
|
||||
if (dst != address(0)) {
|
||||
(uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
|
||||
emit DelegateVotesChanged(dst, oldWeight, newWeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _writeCheckpoint(
|
||||
Checkpoint[] storage ckpts,
|
||||
function(uint256, uint256) view returns (uint256) op,
|
||||
uint256 delta
|
||||
) private returns (uint256 oldWeight, uint256 newWeight) {
|
||||
uint256 pos = ckpts.length;
|
||||
|
||||
unchecked {
|
||||
Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);
|
||||
|
||||
oldWeight = oldCkpt.votes;
|
||||
newWeight = op(oldWeight, delta);
|
||||
|
||||
if (pos > 0 && oldCkpt.fromBlock == block.number) {
|
||||
_unsafeAccess(ckpts, pos - 1).votes = SafeCast.toUint224(newWeight);
|
||||
} else {
|
||||
ckpts.push(
|
||||
Checkpoint({fromBlock: SafeCast.toUint32(block.number), votes: SafeCast.toUint224(newWeight)})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _add(uint256 a, uint256 b) private pure returns (uint256) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function _subtract(uint256 a, uint256 b) private pure returns (uint256) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
|
||||
*/
|
||||
function _unsafeAccess(Checkpoint[] storage ckpts, uint256 pos) private pure returns (Checkpoint storage result) {
|
||||
assembly {
|
||||
mstore(0, ckpts.slot)
|
||||
result.slot := add(keccak256(0, 0x20), pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/extensions/ERC4626.sol";
|
||||
|
||||
abstract contract ERC4626OffsetMock is ERC4626 {
|
||||
uint8 private immutable _offset;
|
||||
|
||||
constructor(uint8 offset_) {
|
||||
_offset = offset_;
|
||||
}
|
||||
|
||||
function _decimalsOffset() internal view virtual override returns (uint8) {
|
||||
return _offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../docs/ERC4626Fees.sol";
|
||||
|
||||
abstract contract ERC4626FeesMock is ERC4626Fees {
|
||||
uint256 private immutable _entryFeeBasePointValue;
|
||||
address private immutable _entryFeeRecipientValue;
|
||||
uint256 private immutable _exitFeeBasePointValue;
|
||||
address private immutable _exitFeeRecipientValue;
|
||||
|
||||
constructor(
|
||||
uint256 entryFeeBasePoint,
|
||||
address entryFeeRecipient,
|
||||
uint256 exitFeeBasePoint,
|
||||
address exitFeeRecipient
|
||||
) {
|
||||
_entryFeeBasePointValue = entryFeeBasePoint;
|
||||
_entryFeeRecipientValue = entryFeeRecipient;
|
||||
_exitFeeBasePointValue = exitFeeBasePoint;
|
||||
_exitFeeRecipientValue = exitFeeRecipient;
|
||||
}
|
||||
|
||||
function _entryFeeBasePoint() internal view virtual override returns (uint256) {
|
||||
return _entryFeeBasePointValue;
|
||||
}
|
||||
|
||||
function _entryFeeRecipient() internal view virtual override returns (address) {
|
||||
return _entryFeeRecipientValue;
|
||||
}
|
||||
|
||||
function _exitFeeBasePoint() internal view virtual override returns (uint256) {
|
||||
return _exitFeeBasePointValue;
|
||||
}
|
||||
|
||||
function _exitFeeRecipient() internal view virtual override returns (address) {
|
||||
return _exitFeeRecipientValue;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC721/extensions/ERC721Consecutive.sol";
|
||||
import "../../token/ERC721/extensions/ERC721Enumerable.sol";
|
||||
|
||||
contract ERC721ConsecutiveEnumerableMock is ERC721Consecutive, ERC721Enumerable {
|
||||
constructor(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
address[] memory receivers,
|
||||
uint96[] memory amounts
|
||||
) ERC721(name, symbol) {
|
||||
for (uint256 i = 0; i < receivers.length; ++i) {
|
||||
_mintConsecutive(receivers[i], amounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function supportsInterface(
|
||||
bytes4 interfaceId
|
||||
) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
|
||||
return super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
function _ownerOf(uint256 tokenId) internal view virtual override(ERC721, ERC721Consecutive) returns (address) {
|
||||
return super._ownerOf(tokenId);
|
||||
}
|
||||
|
||||
function _mint(address to, uint256 tokenId) internal virtual override(ERC721, ERC721Consecutive) {
|
||||
super._mint(to, tokenId);
|
||||
}
|
||||
|
||||
function _beforeTokenTransfer(
|
||||
address from,
|
||||
address to,
|
||||
uint256 firstTokenId,
|
||||
uint256 batchSize
|
||||
) internal virtual override(ERC721, ERC721Enumerable) {
|
||||
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
|
||||
}
|
||||
|
||||
function _afterTokenTransfer(
|
||||
address from,
|
||||
address to,
|
||||
uint256 firstTokenId,
|
||||
uint256 batchSize
|
||||
) internal virtual override(ERC721, ERC721Consecutive) {
|
||||
super._afterTokenTransfer(from, to, firstTokenId, batchSize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC721/extensions/ERC721Consecutive.sol";
|
||||
import "../../token/ERC721/extensions/ERC721Enumerable.sol";
|
||||
import "../../token/ERC721/extensions/ERC721Pausable.sol";
|
||||
import "../../token/ERC721/extensions/draft-ERC721Votes.sol";
|
||||
|
||||
/**
|
||||
* @title ERC721ConsecutiveMock
|
||||
*/
|
||||
contract ERC721ConsecutiveMock is ERC721Consecutive, ERC721Pausable, ERC721Votes {
|
||||
constructor(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
address[] memory delegates,
|
||||
address[] memory receivers,
|
||||
uint96[] memory amounts
|
||||
) ERC721(name, symbol) EIP712(name, "1") {
|
||||
for (uint256 i = 0; i < delegates.length; ++i) {
|
||||
_delegate(delegates[i], delegates[i]);
|
||||
}
|
||||
|
||||
for (uint256 i = 0; i < receivers.length; ++i) {
|
||||
_mintConsecutive(receivers[i], amounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function _ownerOf(uint256 tokenId) internal view virtual override(ERC721, ERC721Consecutive) returns (address) {
|
||||
return super._ownerOf(tokenId);
|
||||
}
|
||||
|
||||
function _mint(address to, uint256 tokenId) internal virtual override(ERC721, ERC721Consecutive) {
|
||||
super._mint(to, tokenId);
|
||||
}
|
||||
|
||||
function _beforeTokenTransfer(
|
||||
address from,
|
||||
address to,
|
||||
uint256 firstTokenId,
|
||||
uint256 batchSize
|
||||
) internal virtual override(ERC721, ERC721Pausable) {
|
||||
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
|
||||
}
|
||||
|
||||
function _afterTokenTransfer(
|
||||
address from,
|
||||
address to,
|
||||
uint256 firstTokenId,
|
||||
uint256 batchSize
|
||||
) internal virtual override(ERC721, ERC721Votes, ERC721Consecutive) {
|
||||
super._afterTokenTransfer(from, to, firstTokenId, batchSize);
|
||||
}
|
||||
}
|
||||
|
||||
contract ERC721ConsecutiveNoConstructorMintMock is ERC721Consecutive {
|
||||
constructor(string memory name, string memory symbol) ERC721(name, symbol) {
|
||||
_mint(msg.sender, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC721/IERC721Receiver.sol";
|
||||
|
||||
contract ERC721ReceiverMock is IERC721Receiver {
|
||||
enum Error {
|
||||
None,
|
||||
RevertWithMessage,
|
||||
RevertWithoutMessage,
|
||||
Panic
|
||||
}
|
||||
|
||||
bytes4 private immutable _retval;
|
||||
Error private immutable _error;
|
||||
|
||||
event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas);
|
||||
|
||||
constructor(bytes4 retval, Error error) {
|
||||
_retval = retval;
|
||||
_error = error;
|
||||
}
|
||||
|
||||
function onERC721Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 tokenId,
|
||||
bytes memory data
|
||||
) public override returns (bytes4) {
|
||||
if (_error == Error.RevertWithMessage) {
|
||||
revert("ERC721ReceiverMock: reverting");
|
||||
} else if (_error == Error.RevertWithoutMessage) {
|
||||
revert();
|
||||
} else if (_error == Error.Panic) {
|
||||
uint256 a = uint256(0) / uint256(0);
|
||||
a;
|
||||
}
|
||||
emit Received(operator, from, tokenId, data, gasleft());
|
||||
return _retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC721/extensions/ERC721URIStorage.sol";
|
||||
|
||||
abstract contract ERC721URIStorageMock is ERC721URIStorage {
|
||||
string private _baseTokenURI;
|
||||
|
||||
function _baseURI() internal view virtual override returns (string memory) {
|
||||
return _baseTokenURI;
|
||||
}
|
||||
|
||||
function setBaseURI(string calldata newBaseTokenURI) public {
|
||||
_baseTokenURI = newBaseTokenURI;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC777/ERC777.sol";
|
||||
|
||||
abstract contract ERC777Mock is ERC777 {
|
||||
event BeforeTokenTransfer();
|
||||
|
||||
function _beforeTokenTransfer(address, address, address, uint256) internal override {
|
||||
emit BeforeTokenTransfer();
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC777/IERC777.sol";
|
||||
import "../../token/ERC777/IERC777Sender.sol";
|
||||
import "../../token/ERC777/IERC777Recipient.sol";
|
||||
import "../../utils/Context.sol";
|
||||
import "../../utils/introspection/IERC1820Registry.sol";
|
||||
import "../../utils/introspection/ERC1820Implementer.sol";
|
||||
|
||||
contract ERC777SenderRecipientMock is Context, IERC777Sender, IERC777Recipient, ERC1820Implementer {
|
||||
event TokensToSendCalled(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount,
|
||||
bytes data,
|
||||
bytes operatorData,
|
||||
address token,
|
||||
uint256 fromBalance,
|
||||
uint256 toBalance
|
||||
);
|
||||
|
||||
event TokensReceivedCalled(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount,
|
||||
bytes data,
|
||||
bytes operatorData,
|
||||
address token,
|
||||
uint256 fromBalance,
|
||||
uint256 toBalance
|
||||
);
|
||||
|
||||
// Emitted in ERC777Mock. Here for easier decoding
|
||||
event BeforeTokenTransfer();
|
||||
|
||||
bool private _shouldRevertSend;
|
||||
bool private _shouldRevertReceive;
|
||||
|
||||
IERC1820Registry private _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
|
||||
|
||||
bytes32 private constant _TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
|
||||
bytes32 private constant _TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
|
||||
|
||||
function tokensToSend(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount,
|
||||
bytes calldata userData,
|
||||
bytes calldata operatorData
|
||||
) external override {
|
||||
if (_shouldRevertSend) {
|
||||
revert();
|
||||
}
|
||||
|
||||
IERC777 token = IERC777(_msgSender());
|
||||
|
||||
uint256 fromBalance = token.balanceOf(from);
|
||||
// when called due to burn, to will be the zero address, which will have a balance of 0
|
||||
uint256 toBalance = token.balanceOf(to);
|
||||
|
||||
emit TokensToSendCalled(
|
||||
operator,
|
||||
from,
|
||||
to,
|
||||
amount,
|
||||
userData,
|
||||
operatorData,
|
||||
address(token),
|
||||
fromBalance,
|
||||
toBalance
|
||||
);
|
||||
}
|
||||
|
||||
function tokensReceived(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount,
|
||||
bytes calldata userData,
|
||||
bytes calldata operatorData
|
||||
) external override {
|
||||
if (_shouldRevertReceive) {
|
||||
revert();
|
||||
}
|
||||
|
||||
IERC777 token = IERC777(_msgSender());
|
||||
|
||||
uint256 fromBalance = token.balanceOf(from);
|
||||
// when called due to burn, to will be the zero address, which will have a balance of 0
|
||||
uint256 toBalance = token.balanceOf(to);
|
||||
|
||||
emit TokensReceivedCalled(
|
||||
operator,
|
||||
from,
|
||||
to,
|
||||
amount,
|
||||
userData,
|
||||
operatorData,
|
||||
address(token),
|
||||
fromBalance,
|
||||
toBalance
|
||||
);
|
||||
}
|
||||
|
||||
function senderFor(address account) public {
|
||||
_registerInterfaceForAddress(_TOKENS_SENDER_INTERFACE_HASH, account);
|
||||
|
||||
address self = address(this);
|
||||
if (account == self) {
|
||||
registerSender(self);
|
||||
}
|
||||
}
|
||||
|
||||
function registerSender(address sender) public {
|
||||
_erc1820.setInterfaceImplementer(address(this), _TOKENS_SENDER_INTERFACE_HASH, sender);
|
||||
}
|
||||
|
||||
function recipientFor(address account) public {
|
||||
_registerInterfaceForAddress(_TOKENS_RECIPIENT_INTERFACE_HASH, account);
|
||||
|
||||
address self = address(this);
|
||||
if (account == self) {
|
||||
registerRecipient(self);
|
||||
}
|
||||
}
|
||||
|
||||
function registerRecipient(address recipient) public {
|
||||
_erc1820.setInterfaceImplementer(address(this), _TOKENS_RECIPIENT_INTERFACE_HASH, recipient);
|
||||
}
|
||||
|
||||
function setShouldRevertSend(bool shouldRevert) public {
|
||||
_shouldRevertSend = shouldRevert;
|
||||
}
|
||||
|
||||
function setShouldRevertReceive(bool shouldRevert) public {
|
||||
_shouldRevertReceive = shouldRevert;
|
||||
}
|
||||
|
||||
function send(IERC777 token, address to, uint256 amount, bytes memory data) public {
|
||||
// This is 777's send function, not the Solidity send function
|
||||
token.send(to, amount, data); // solhint-disable-line check-send-result
|
||||
}
|
||||
|
||||
function burn(IERC777 token, uint256 amount, bytes memory data) public {
|
||||
token.burn(amount, data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../../token/ERC20/extensions/ERC20Votes.sol";
|
||||
import "../../token/ERC20/extensions/ERC20VotesComp.sol";
|
||||
import "../../token/ERC721/extensions/ERC721Votes.sol";
|
||||
|
||||
abstract contract ERC20VotesTimestampMock is ERC20Votes {
|
||||
function clock() public view virtual override returns (uint48) {
|
||||
return SafeCast.toUint48(block.timestamp);
|
||||
}
|
||||
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function CLOCK_MODE() public view virtual override returns (string memory) {
|
||||
return "mode=timestamp";
|
||||
}
|
||||
}
|
||||
|
||||
abstract contract ERC20VotesCompTimestampMock is ERC20VotesComp {
|
||||
function clock() public view virtual override returns (uint48) {
|
||||
return SafeCast.toUint48(block.timestamp);
|
||||
}
|
||||
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function CLOCK_MODE() public view virtual override returns (string memory) {
|
||||
return "mode=timestamp";
|
||||
}
|
||||
}
|
||||
|
||||
abstract contract ERC721VotesTimestampMock is ERC721Votes {
|
||||
function clock() public view virtual override returns (uint48) {
|
||||
return SafeCast.toUint48(block.timestamp);
|
||||
}
|
||||
|
||||
// solhint-disable-next-line func-name-mixedcase
|
||||
function CLOCK_MODE() public view virtual override returns (string memory) {
|
||||
return "mode=timestamp";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user