From 33e8f522b47c9ce7443b10405b6e45c6fb879d21 Mon Sep 17 00:00:00 2001 From: turupawn Date: Sun, 5 Feb 2023 17:32:47 -0600 Subject: [PATCH] prettiered --- contracts/ERC20/BalancerV2FeeToken.sol | 50 ++-- contracts/ERC20/ERC20.sol | 65 ++++- contracts/ERC20/UniswapV2AutoSwapToken.sol | 50 ++-- contracts/ERC20/UniswapV2FeeToken.sol | 75 +++--- contracts/ERC20/UniswapV3FeeToken.sol | 87 ++++--- .../ERC20/interfaces/BalancerInterfaces.sol | 15 +- contracts/ERC20/interfaces/IWETH.sol | 2 +- .../ERC20/interfaces/UniswapV2Interfaces.sol | 13 +- .../ERC20/interfaces/UniswapV3Interfaces.sol | 76 +++--- contracts/ERC721/ERC721.sol | 239 ++++++++++++++---- contracts/ERC721/ERC721a.sol | 228 +++++++++++++---- contracts/ERC721/ERC721aCollection.sol | 16 +- .../ERC721/OpenZeppelinNFTCollection.sol | 16 +- contracts/common/Address.sol | 101 ++++++-- contracts/common/Context.sol | 2 +- contracts/common/Counters.sol | 2 +- contracts/common/Ownable.sol | 12 +- contracts/common/Strings.sol | 69 ++++- .../examples/ERC20/MyBalancerFeeToken.sol | 23 +- .../ERC20/MyUniswapV2AutoSwapToken.sol | 29 ++- .../examples/ERC20/MyUniswapV2FeeToken.sol | 27 +- .../examples/ERC20/MyUniswapV3FeeToken.sol | 26 +- .../examples/ERC721/MyERC721aCollection.sol | 21 +- .../ERC721/MyOpenZeppelinNFTCollection.sol | 21 +- package-lock.json | 58 ++++- package.json | 2 + 26 files changed, 905 insertions(+), 420 deletions(-) diff --git a/contracts/ERC20/BalancerV2FeeToken.sol b/contracts/ERC20/BalancerV2FeeToken.sol index c79f72d..0059b87 100644 --- a/contracts/ERC20/BalancerV2FeeToken.sol +++ b/contracts/ERC20/BalancerV2FeeToken.sol @@ -10,8 +10,7 @@ import "./interfaces/BalancerInterfaces.sol"; /// @author Filosofía Codigo /// @notice You can use this contract launch your own token or to study the Balancer ecosystem. /// @dev Based on top OpenZeppelin contracts but changed balances from private to internal for flexibility -abstract contract BalancerV2FeeToken is ERC20 -{ +abstract contract BalancerV2FeeToken is ERC20 { /// @notice List of address that won't pay transaction fees mapping(address => bool) public isTaxless; /// @notice Address that will recieve fees taken from each transaction @@ -34,14 +33,17 @@ abstract contract BalancerV2FeeToken is ERC20 /// @param sellFeePercentage Percent of tokens that will be sent to the feeReciever when token is sold on Balancer /// @param p2pFeePercentage Percent of tokens that will be sent to the feeReciever when token is transfered outside of Balancer /// @param feeReceiver_ Address that will recieve the fees taken every transaction - constructor(string memory name, string memory symbol, + constructor( + string memory name, + string memory symbol, uint totalSupply_, - uint buyFeePercentage, uint sellFeePercentage, uint p2pFeePercentage, - address feeReceiver_) - ERC20(name, symbol, totalSupply_) - { + uint buyFeePercentage, + uint sellFeePercentage, + uint p2pFeePercentage, + address feeReceiver_ + ) ERC20(name, symbol, totalSupply_) { feeReceiver = feeReceiver_; - + isTaxless[msg.sender] = true; isTaxless[address(this)] = true; isTaxless[feeReceiver] = true; @@ -50,7 +52,7 @@ abstract contract BalancerV2FeeToken is ERC20 fees.push(buyFeePercentage); fees.push(sellFeePercentage); fees.push(p2pFeePercentage); - + isFeeActive = true; } @@ -65,11 +67,11 @@ abstract contract BalancerV2FeeToken is ERC20 bool sell = to == balancerVault; bool p2p = from != balancerVault && to != balancerVault; uint feeIndex = 0; - if(p2p) - feeIndex = 2; - else if(sell) - feeIndex = 1; - feesCollected = (amount * fees[feeIndex]) / (10**(feeDecimals + 2)); + if (p2p) feeIndex = 2; + else if (sell) feeIndex = 1; + feesCollected = + (amount * fees[feeIndex]) / + (10 ** (feeDecimals + 2)); } amount -= feesCollected; @@ -77,7 +79,7 @@ abstract contract BalancerV2FeeToken is ERC20 _balances[feeReceiver] += feesCollected; emit Transfer(from, feeReceiver, amount); - + super._transfer(from, to, amount); } @@ -85,24 +87,21 @@ abstract contract BalancerV2FeeToken is ERC20 /// @param account Address that tax configuration will be affected /// @param isTaxless_ If set to true the account will not pay transaction fees /// @custom:internal This function is internal, can be overrided. - function _setTaxless(address account, bool isTaxless_) internal - { + function _setTaxless(address account, bool isTaxless_) internal { isTaxless[account] = isTaxless_; } /// @notice Changes the address that will recieve fees /// @param feeReceiver_ If set to true the account will not pay transaction fees /// @custom:internal This function is internal, can be overrided. - function _setFeeReceiver(address feeReceiver_) internal - { + function _setFeeReceiver(address feeReceiver_) internal { feeReceiver = feeReceiver_; } /// @notice Changes the address that will recieve fees /// @param isFeeActive_ If set to true all transaction fees will not be charged /// @custom:internal This function is internal, can be overrided. - function _setFeeActive(bool isFeeActive_) internal - { + function _setFeeActive(bool isFeeActive_) internal { isFeeActive = isFeeActive_; } @@ -111,10 +110,13 @@ abstract contract BalancerV2FeeToken is ERC20 /// @param sellFeePercentage New sell percentage fee /// @param p2pFeePercentage New peer to peer percentage fee /// @custom:internal This function is internal, can be overrided. - function _setFees(uint buyFeePercentage, uint sellFeePercentage, uint p2pFeePercentage) internal - { + function _setFees( + uint buyFeePercentage, + uint sellFeePercentage, + uint p2pFeePercentage + ) internal { fees[0] = buyFeePercentage; fees[1] = sellFeePercentage; fees[2] = p2pFeePercentage; } -} \ No newline at end of file +} diff --git a/contracts/ERC20/ERC20.sol b/contracts/ERC20/ERC20.sol index dcf04b4..12a6cd4 100644 --- a/contracts/ERC20/ERC20.sol +++ b/contracts/ERC20/ERC20.sol @@ -7,12 +7,25 @@ import "../common/Ownable.sol"; interface IERC20 { event Transfer(address indexed from, address indexed to, uint256 value); - event Approval(address indexed owner, address indexed spender, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); + function totalSupply() external view returns (uint256); + function balanceOf(address account) external view returns (uint256); + function transfer(address to, uint256 amount) external returns (bool); - function allowance(address owner, address spender) external view returns (uint256); + + function allowance( + address owner, + address spender + ) external view returns (uint256); + function approve(address spender, uint256 amount) external returns (bool); + function transferFrom( address from, address to, @@ -22,7 +35,9 @@ interface IERC20 { interface IERC20Metadata is IERC20 { function name() external view returns (string memory); + function symbol() external view returns (string memory); + function decimals() external view returns (uint8); } @@ -58,21 +73,32 @@ contract ERC20 is Context, IERC20, IERC20Metadata, Ownable { return _totalSupply; } - function balanceOf(address account) public view virtual override returns (uint256) { + function balanceOf( + address account + ) public view virtual override returns (uint256) { return _balances[account]; } - function transfer(address to, uint256 amount) public virtual override returns (bool) { + function transfer( + address to, + uint256 amount + ) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } - function allowance(address owner, address spender) public view virtual override returns (uint256) { + function allowance( + address owner, + address spender + ) public view virtual override returns (uint256) { return _allowances[owner][spender]; } - function approve(address spender, uint256 amount) public virtual override returns (bool) { + function approve( + address spender, + uint256 amount + ) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; @@ -89,16 +115,25 @@ contract ERC20 is Context, IERC20, IERC20Metadata, Ownable { return true; } - function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + function increaseAllowance( + address spender, + uint256 addedValue + ) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } - function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + function decreaseAllowance( + address spender, + uint256 subtractedValue + ) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); - require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); + require( + currentAllowance >= subtractedValue, + "ERC20: decreased allowance below zero" + ); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } @@ -117,7 +152,10 @@ contract ERC20 is Context, IERC20, IERC20Metadata, Ownable { _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; - require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); + require( + fromBalance >= amount, + "ERC20: transfer amount exceeds balance" + ); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by @@ -182,7 +220,10 @@ contract ERC20 is Context, IERC20, IERC20Metadata, Ownable { ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { - require(currentAllowance >= amount, "ERC20: insufficient allowance"); + require( + currentAllowance >= amount, + "ERC20: insufficient allowance" + ); unchecked { _approve(owner, spender, currentAllowance - amount); } @@ -200,4 +241,4 @@ contract ERC20 is Context, IERC20, IERC20Metadata, Ownable { address to, uint256 amount ) internal virtual {} -} \ No newline at end of file +} diff --git a/contracts/ERC20/UniswapV2AutoSwapToken.sol b/contracts/ERC20/UniswapV2AutoSwapToken.sol index 0994398..2a0d463 100644 --- a/contracts/ERC20/UniswapV2AutoSwapToken.sol +++ b/contracts/ERC20/UniswapV2AutoSwapToken.sol @@ -10,8 +10,7 @@ import "./interfaces/UniswapV2Interfaces.sol"; /// @author Filosofía Codigo /// @notice You can use this contract launch your own token or to study the Uniswap V2 ecosystem. /// @dev Based on top OpenZeppelin contracts but changed balances from private to internal for flexibility -abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken -{ +abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken { /// @notice Percentage of total supply that have to be accumulated as fees to trigger the autoswap and send the fees to the autoSwapReciever uint256 public minTokensBeforeSwap; /// @notice Address that will recieve fees on base token denomination @@ -33,18 +32,28 @@ abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken /// @param routerAddress You can support such DEXes by setting the router address in this param. Many projects such as Pancakeswap, Sushiswap or Quickswap are compatible with Uniswap V2 /// @param baseTokenAddress Token address that this will be paired with on the DEX. Fees will be sent to the autoSwapReciever in the base token denomination /// @param minTokensBeforeSwapPercent Percentage of total supply that have to be accumulated as fees to trigger the autoswap and send the fees to the autoSwapReciever - constructor(string memory name, string memory symbol, + constructor( + string memory name, + string memory symbol, uint totalSupply_, - uint buyFeePercentage, uint sellFeePercentage, uint p2pFeePercentage, + uint buyFeePercentage, + uint sellFeePercentage, + uint p2pFeePercentage, address autoSwapReciever_, address routerAddress, address baseTokenAddress, - uint minTokensBeforeSwapPercent) UniswapV2FeeToken(name, symbol, - totalSupply_, - buyFeePercentage, sellFeePercentage, p2pFeePercentage, - address(this), - routerAddress, - baseTokenAddress + uint minTokensBeforeSwapPercent + ) + UniswapV2FeeToken( + name, + symbol, + totalSupply_, + buyFeePercentage, + sellFeePercentage, + p2pFeePercentage, + address(this), + routerAddress, + baseTokenAddress ) { autoSwapReciever = autoSwapReciever_; @@ -62,12 +71,12 @@ abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken /// @dev Swaps all the fees collected to base tokens and send it to the autoSwapReciever function swap() private lockTheSwap { uint totalSwap = balanceOf(address(this)); - if(minTokensBeforeSwap > totalSwap) return; - if(totalSwap <= 0) return; + if (minTokensBeforeSwap > totalSwap) return; + if (totalSwap <= 0) return; address[] memory sellPath = new address[](2); sellPath[0] = address(this); - sellPath[1] = address(baseToken); + sellPath[1] = address(baseToken); _approve(address(this), address(router), totalSwap); router.swapExactTokensForTokensSupportingFeeOnTransferTokens( @@ -77,7 +86,7 @@ abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken autoSwapReciever, block.timestamp ); - + emit Swap(totalSwap); } @@ -87,8 +96,7 @@ abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken address to, uint256 amount ) internal virtual override { - if(isFeeActive) - { + if (isFeeActive) { swap(); } super._transfer(from, to, amount); @@ -96,7 +104,11 @@ abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken /// @notice Change the minimum ammount of fees collected to trigger the autoswap /// @param percentage Percentage of total supply that have to be accumulated as fees to trigger the autoswap and send the fees to the autoSwapReciever - function setMinTokensBeforeSwapPercent(uint256 percentage) public onlyOwner { - minTokensBeforeSwap = (totalSupply() * percentage) / (10**(feeDecimals + 2)); + function setMinTokensBeforeSwapPercent( + uint256 percentage + ) public onlyOwner { + minTokensBeforeSwap = + (totalSupply() * percentage) / + (10 ** (feeDecimals + 2)); } -} \ No newline at end of file +} diff --git a/contracts/ERC20/UniswapV2FeeToken.sol b/contracts/ERC20/UniswapV2FeeToken.sol index 77f46c0..3cda4a4 100644 --- a/contracts/ERC20/UniswapV2FeeToken.sol +++ b/contracts/ERC20/UniswapV2FeeToken.sol @@ -10,8 +10,7 @@ import "./interfaces/UniswapV2Interfaces.sol"; /// @author Filosofía Codigo /// @notice You can use this contract launch your own token or to study the Uniswap V2 ecosystem. /// @dev Based on top OpenZeppelin contracts but changed balances from private to internal for flexibility -abstract contract UniswapV2FeeToken is ERC20 -{ +abstract contract UniswapV2FeeToken is ERC20 { /// @notice List of address that won't pay transaction fees mapping(address => bool) public isTaxless; /// @notice Address that will recieve fees taken from each transaction @@ -40,19 +39,26 @@ abstract contract UniswapV2FeeToken is ERC20 /// @param feeReceiver_ Address that will recieve the fees taken every transaction /// @param routerAddress You can support such DEXes by setting the router address in this param. Many projects such as Pancakeswap, Sushiswap or Quickswap are compatible with Uniswap V2 /// @param baseTokenAddress Token address that this will be paired with on the DEX. Fees will be sent to the autoSwapReciever in the base token denomination - constructor(string memory name, string memory symbol, + constructor( + string memory name, + string memory symbol, uint totalSupply_, - uint buyFeePercentage, uint sellFeePercentage, uint p2pFeePercentage, + uint buyFeePercentage, + uint sellFeePercentage, + uint p2pFeePercentage, address feeReceiver_, address routerAddress, - address baseTokenAddress) ERC20(name, symbol, totalSupply_) - { + address baseTokenAddress + ) ERC20(name, symbol, totalSupply_) { router = ISwapRouter(routerAddress); - pair = ISwapFactory(router.factory()).createPair(address(this), baseTokenAddress); + pair = ISwapFactory(router.factory()).createPair( + address(this), + baseTokenAddress + ); baseToken = IERC20(baseTokenAddress); - + feeReceiver = feeReceiver_; - + isTaxless[msg.sender] = true; isTaxless[address(this)] = true; isTaxless[feeReceiver] = true; @@ -61,7 +67,7 @@ abstract contract UniswapV2FeeToken is ERC20 fees.push(buyFeePercentage); fees.push(sellFeePercentage); fees.push(p2pFeePercentage); - + isFeeActive = true; } @@ -70,18 +76,17 @@ abstract contract UniswapV2FeeToken is ERC20 address from, address to, uint256 amount - ) internal virtual override - { + ) internal virtual override { uint256 feesCollected; if (isFeeActive && !isTaxless[from] && !isTaxless[to]) { bool sell = to == pair; bool p2p = from != pair && to != pair; uint feeIndex = 0; - if(p2p) - feeIndex = 2; - else if(sell) - feeIndex = 1; - feesCollected = (amount * fees[feeIndex]) / (10**(feeDecimals + 2)); + if (p2p) feeIndex = 2; + else if (sell) feeIndex = 1; + feesCollected = + (amount * fees[feeIndex]) / + (10 ** (feeDecimals + 2)); } amount -= feesCollected; @@ -89,7 +94,7 @@ abstract contract UniswapV2FeeToken is ERC20 _balances[feeReceiver] += feesCollected; emit Transfer(from, feeReceiver, amount); - + super._transfer(from, to, amount); } @@ -97,24 +102,21 @@ abstract contract UniswapV2FeeToken is ERC20 /// @param account Address that tax configuration will be affected /// @param isTaxless_ If set to true the account will not pay transaction fees /// @custom:internal This function is internal, can be overrided. - function _setTaxless(address account, bool isTaxless_) internal - { + function _setTaxless(address account, bool isTaxless_) internal { isTaxless[account] = isTaxless_; } /// @notice Changes the address that will recieve fees /// @param feeReceiver_ If set to true the account will not pay transaction fees /// @custom:internal This function is internal, can be overrided. - function _setFeeReceiver(address feeReceiver_) internal - { + function _setFeeReceiver(address feeReceiver_) internal { feeReceiver = feeReceiver_; } /// @notice Changes the address that will recieve fees /// @param isFeeActive_ If set to true all transaction fees will not be charged /// @custom:internal This function is internal, can be overrided. - function _setFeeActive(bool isFeeActive_) internal - { + function _setFeeActive(bool isFeeActive_) internal { isFeeActive = isFeeActive_; } @@ -123,8 +125,11 @@ abstract contract UniswapV2FeeToken is ERC20 /// @param sellFeePercentage New sell percentage fee /// @param p2pFeePercentage New peer to peer percentage fee /// @custom:internal This function is internal, can be overrided. - function _setFees(uint buyFeePercentage, uint sellFeePercentage, uint p2pFeePercentage) internal - { + function _setFees( + uint buyFeePercentage, + uint sellFeePercentage, + uint p2pFeePercentage + ) internal { fees[0] = buyFeePercentage; fees[1] = sellFeePercentage; fees[2] = p2pFeePercentage; @@ -134,14 +139,18 @@ abstract contract UniswapV2FeeToken is ERC20 /// @param router_ New router that will be updated /// @param baseToken_ New base token that will be used /// @custom:internal This function is internal, can be overrided. - function _setPair(address router_, address baseToken_) internal - { + function _setPair(address router_, address baseToken_) internal { router = ISwapRouter(router_); baseToken = IERC20(baseToken_); - pair = ISwapFactory(router.factory()).getPair(address(this), address(baseToken)); - if(pair == address(0)) - { - pair = ISwapFactory(router.factory()).createPair(address(this), address(baseToken)); + pair = ISwapFactory(router.factory()).getPair( + address(this), + address(baseToken) + ); + if (pair == address(0)) { + pair = ISwapFactory(router.factory()).createPair( + address(this), + address(baseToken) + ); } } -} \ No newline at end of file +} diff --git a/contracts/ERC20/UniswapV3FeeToken.sol b/contracts/ERC20/UniswapV3FeeToken.sol index 71f4248..3f58011 100644 --- a/contracts/ERC20/UniswapV3FeeToken.sol +++ b/contracts/ERC20/UniswapV3FeeToken.sol @@ -10,8 +10,7 @@ import "./interfaces/UniswapV3Interfaces.sol"; /// @author Filosofía Codigo /// @notice You can use this contract launch your own token or to study the Uniswap V3 ecosystem. /// @dev Based on top OpenZeppelin contracts but changed balances from private to internal for flexibility -abstract contract UniswapV3FeeToken is ERC20 -{ +abstract contract UniswapV3FeeToken is ERC20 { /// @notice List of address that won't pay transaction fees mapping(address => bool) public isTaxless; /// @notice Address that will recieve fees taken from each transaction @@ -36,8 +35,8 @@ abstract contract UniswapV3FeeToken is ERC20 address public pool4; /// @notice Uniswap V3 Position Manager used to gather the pool addresses - INonfungiblePositionManager public nonfungiblePositionManager - = INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88); + INonfungiblePositionManager public nonfungiblePositionManager = + INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88); /// @notice Contract constructor /// @dev All percentage numbers are two digit decimals. For example 250 means 2.5% @@ -49,16 +48,19 @@ abstract contract UniswapV3FeeToken is ERC20 /// @param feeReceiver_ Address that will recieve the fees taken every transaction /// @param baseTokenAddress Token address that this will be paired with on the DEX. Fees will be sent to the autoSwapReciever in the base token denomination /// @param rate Initial token value in the form of 1 base token = `rate` tokens - constructor(string memory name, string memory symbol, + constructor( + string memory name, + string memory symbol, uint totalSupply_, - uint buyFeePercentage_, uint p2pFeePercentage_, + uint buyFeePercentage_, + uint p2pFeePercentage_, address feeReceiver_, address baseTokenAddress, - uint160 rate) ERC20(name, symbol, totalSupply_) - { + uint160 rate + ) ERC20(name, symbol, totalSupply_) { feeReceiver = feeReceiver_; baseToken = IERC20(baseTokenAddress); - + isTaxless[msg.sender] = true; isTaxless[address(this)] = true; isTaxless[feeReceiver] = true; @@ -69,12 +71,10 @@ abstract contract UniswapV3FeeToken is ERC20 address token0; address token1; - if(address(this) < baseTokenAddress) - { + if (address(this) < baseTokenAddress) { token0 = address(this); token1 = baseTokenAddress; - }else - { + } else { token0 = baseTokenAddress; token1 = address(this); } @@ -82,37 +82,35 @@ abstract contract UniswapV3FeeToken is ERC20 uint160 RATE = rate; uint160 sqrtPriceX96; - if(token0 == baseTokenAddress) - { + if (token0 == baseTokenAddress) { sqrtPriceX96 = uint160(sqrt(RATE)) * 2 ** 96; - }else - { + } else { sqrtPriceX96 = (2 ** 96) / uint160(sqrt(RATE)); } pool1 = nonfungiblePositionManager.createAndInitializePoolIfNecessary( token0, token1, - 100/* fee */, - sqrtPriceX96//Math.sqrt("1") * 2 ** 96 + 100 /* fee */, + sqrtPriceX96 //Math.sqrt("1") * 2 ** 96 ); pool2 = nonfungiblePositionManager.createAndInitializePoolIfNecessary( token0, token1, - 500/* fee */, - sqrtPriceX96//Math.sqrt("1") * 2 ** 96 + 500 /* fee */, + sqrtPriceX96 //Math.sqrt("1") * 2 ** 96 ); pool3 = nonfungiblePositionManager.createAndInitializePoolIfNecessary( token0, token1, - 3000/* fee */, - sqrtPriceX96//Math.sqrt("1") * 2 ** 96 + 3000 /* fee */, + sqrtPriceX96 //Math.sqrt("1") * 2 ** 96 ); pool4 = nonfungiblePositionManager.createAndInitializePoolIfNecessary( token0, token1, - 10000/* fee */, - sqrtPriceX96//Math.sqrt("1") * 2 ** 96 + 10000 /* fee */, + sqrtPriceX96 //Math.sqrt("1") * 2 ** 96 ); isFeeActive = true; @@ -126,12 +124,14 @@ abstract contract UniswapV3FeeToken is ERC20 ) internal virtual override { uint256 feesCollected; if (!isTaxless[from] && !isTaxless[to]) { - if(_isPool(from)) - { - feesCollected = (amount * buyFeePercentage) / (10**(feeDecimals + 2)); - }else if(!_isPool(to)) - { - feesCollected = (amount * p2pFeePercentage) / (10**(feeDecimals + 2)); + if (_isPool(from)) { + feesCollected = + (amount * buyFeePercentage) / + (10 ** (feeDecimals + 2)); + } else if (!_isPool(to)) { + feesCollected = + (amount * p2pFeePercentage) / + (10 ** (feeDecimals + 2)); } } @@ -140,14 +140,17 @@ abstract contract UniswapV3FeeToken is ERC20 _balances[feeReceiver] += feesCollected; emit Transfer(from, feeReceiver, amount); - + super._transfer(from, to, amount); } /// @dev Checks if an address is part of the Uniswap V3 pools. This is for internal use. - function _isPool(address _address) internal view returns(bool) - { - return _address == pool1 || _address == pool2 || _address == pool3 || _address == pool4; + function _isPool(address _address) internal view returns (bool) { + return + _address == pool1 || + _address == pool2 || + _address == pool3 || + _address == pool4; } /// @dev Square root function for internal use @@ -168,24 +171,21 @@ abstract contract UniswapV3FeeToken is ERC20 /// @param account Address that tax configuration will be affected /// @param isTaxless_ If set to true the account will not pay transaction fees /// @custom:internal This function is internal, can be overrided. - function _setTaxless(address account, bool isTaxless_) internal - { + function _setTaxless(address account, bool isTaxless_) internal { isTaxless[account] = isTaxless_; } /// @notice Changes the address that will recieve fees /// @param feeReceiver_ If set to true the account will not pay transaction fees /// @custom:internal This function is internal, can be overrided. - function _setFeeReceiver(address feeReceiver_) internal - { + function _setFeeReceiver(address feeReceiver_) internal { feeReceiver = feeReceiver_; } /// @notice Changes the address that will recieve fees /// @param isFeeActive_ If set to true all transaction fees will not be charged /// @custom:internal This function is internal, can be overrided. - function _setFeeActive(bool isFeeActive_) internal - { + function _setFeeActive(bool isFeeActive_) internal { isFeeActive = isFeeActive_; } @@ -193,9 +193,8 @@ abstract contract UniswapV3FeeToken is ERC20 /// @param buyFeePercentage_ New buy percentage fee /// @param p2pFeePercentage_ New peer to peer percentage fee /// @custom:internal This function is internal, can be overrided. - function _setFees(uint buyFeePercentage_, uint p2pFeePercentage_) internal - { + function _setFees(uint buyFeePercentage_, uint p2pFeePercentage_) internal { buyFeePercentage = buyFeePercentage_; p2pFeePercentage = p2pFeePercentage_; } -} \ No newline at end of file +} diff --git a/contracts/ERC20/interfaces/BalancerInterfaces.sol b/contracts/ERC20/interfaces/BalancerInterfaces.sol index 56659b0..4c34625 100644 --- a/contracts/ERC20/interfaces/BalancerInterfaces.sol +++ b/contracts/ERC20/interfaces/BalancerInterfaces.sol @@ -12,7 +12,10 @@ struct JoinPoolRequest { bool fromInternalBalance; } -enum SwapKind { GIVEN_IN, GIVEN_OUT } +enum SwapKind { + GIVEN_IN, + GIVEN_OUT +} struct SingleSwap { bytes32 poolId; @@ -30,8 +33,7 @@ struct FundManagement { bool toInternalBalance; } -interface IVault -{ +interface IVault { function joinPool( bytes32 poolId, address sender, @@ -39,7 +41,6 @@ interface IVault JoinPoolRequest memory request ) external payable; - function swap( SingleSwap memory singleSwap, FundManagement memory funds, @@ -60,8 +61,8 @@ interface IWeightedPool2TokensFactory { ) external returns (address); } -interface IWeightedPool -{ +interface IWeightedPool { function getPoolId() external view returns (bytes32); + function balanceOf(address account) external view returns (uint256); -} \ No newline at end of file +} diff --git a/contracts/ERC20/interfaces/IWETH.sol b/contracts/ERC20/interfaces/IWETH.sol index 40fa02b..cdebbb8 100644 --- a/contracts/ERC20/interfaces/IWETH.sol +++ b/contracts/ERC20/interfaces/IWETH.sol @@ -9,4 +9,4 @@ interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint amount) external; -} \ No newline at end of file +} diff --git a/contracts/ERC20/interfaces/UniswapV2Interfaces.sol b/contracts/ERC20/interfaces/UniswapV2Interfaces.sol index ed61d4d..a618ba9 100644 --- a/contracts/ERC20/interfaces/UniswapV2Interfaces.sol +++ b/contracts/ERC20/interfaces/UniswapV2Interfaces.sol @@ -42,6 +42,13 @@ interface ISwapRouter { } interface ISwapFactory { - function getPair(address tokenA, address tokenB) external view returns (address pair); - function createPair(address tokenA, address tokenB) external returns (address pair); -} \ No newline at end of file + function getPair( + address tokenA, + address tokenB + ) external view returns (address pair); + + function createPair( + address tokenA, + address tokenB + ) external returns (address pair); +} diff --git a/contracts/ERC20/interfaces/UniswapV3Interfaces.sol b/contracts/ERC20/interfaces/UniswapV3Interfaces.sol index 7679f66..47bead9 100644 --- a/contracts/ERC20/interfaces/UniswapV3Interfaces.sol +++ b/contracts/ERC20/interfaces/UniswapV3Interfaces.sol @@ -15,14 +15,12 @@ struct ExactInputSingleParams { } interface IUniswapV3Router { - function exactInputSingle(ExactInputSingleParams calldata params) - external - payable - returns (uint amountOut); + function exactInputSingle( + ExactInputSingleParams calldata params + ) external payable returns (uint amountOut); } interface INonfungiblePositionManager { - function createAndInitializePoolIfNecessary( address token0, address token1, @@ -44,15 +42,12 @@ interface INonfungiblePositionManager { uint deadline; } - function mint(MintParams calldata params) + function mint( + MintParams calldata params + ) external payable - returns ( - uint tokenId, - uint128 liquidity, - uint amount0, - uint amount1 - ); + returns (uint tokenId, uint128 liquidity, uint amount0, uint amount1); struct IncreaseLiquidityParams { uint tokenId; @@ -63,14 +58,9 @@ interface INonfungiblePositionManager { uint deadline; } - function increaseLiquidity(IncreaseLiquidityParams calldata params) - external - payable - returns ( - uint128 liquidity, - uint amount0, - uint amount1 - ); + function increaseLiquidity( + IncreaseLiquidityParams calldata params + ) external payable returns (uint128 liquidity, uint amount0, uint amount1); struct DecreaseLiquidityParams { uint tokenId; @@ -80,10 +70,9 @@ interface INonfungiblePositionManager { uint deadline; } - function decreaseLiquidity(DecreaseLiquidityParams calldata params) - external - payable - returns (uint amount0, uint amount1); + function decreaseLiquidity( + DecreaseLiquidityParams calldata params + ) external payable returns (uint amount0, uint amount1); struct CollectParams { uint tokenId; @@ -92,14 +81,12 @@ interface INonfungiblePositionManager { uint128 amount1Max; } - function collect(CollectParams calldata params) - external - payable - returns (uint amount0, uint amount1); + function collect( + CollectParams calldata params + ) external payable returns (uint amount0, uint amount1); } -abstract contract IUniswapV3Pool -{ +abstract contract IUniswapV3Pool { struct Slot0 { // the current price uint160 sqrtPriceX96; @@ -120,19 +107,22 @@ abstract contract IUniswapV3Pool //Slot0 public slot0; uint24 public fee; + //int24 public tickSpacing; + function slot0() + external + view + virtual + returns ( + uint160 sqrtPriceX96, + int24 tick, + uint16 observationIndex, + uint16 observationCardinality, + uint16 observationCardinalityNext, + uint8 feeProtocol, + bool unlocked + ); - function slot0( - ) external virtual view returns - ( - uint160 sqrtPriceX96, - int24 tick, - uint16 observationIndex, - uint16 observationCardinality, - uint16 observationCardinalityNext, - uint8 feeProtocol, - bool unlocked); - - function tickSpacing() external virtual view returns (int24); -} \ No newline at end of file + function tickSpacing() external view virtual returns (int24); +} diff --git a/contracts/ERC721/ERC721.sol b/contracts/ERC721/ERC721.sol index a5c4eae..03254bd 100644 --- a/contracts/ERC721/ERC721.sol +++ b/contracts/ERC721/ERC721.sol @@ -24,17 +24,29 @@ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ - event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); + event Transfer( + address indexed from, + address indexed to, + uint256 indexed tokenId + ); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ - event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); + event Approval( + address indexed owner, + address indexed approved, + uint256 indexed tokenId + ); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ - event ApprovalForAll(address indexed owner, address indexed operator, bool approved); + event ApprovalForAll( + address indexed owner, + address indexed operator, + bool approved + ); /** * @dev Returns the number of tokens in ``owner``'s account. @@ -63,7 +75,12 @@ interface IERC721 is IERC165 { * * Emits a {Transfer} event. */ - function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; + function safeTransferFrom( + address from, + address to, + uint256 tokenId, + bytes calldata data + ) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients @@ -79,7 +96,11 @@ interface IERC721 is IERC165 { * * Emits a {Transfer} event. */ - function safeTransferFrom(address from, address to, uint256 tokenId) external; + function safeTransferFrom( + address from, + address to, + uint256 tokenId + ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. @@ -133,14 +154,19 @@ interface IERC721 is IERC165 { * * - `tokenId` must exist. */ - function getApproved(uint256 tokenId) external view returns (address operator); + function getApproved( + uint256 tokenId + ) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ - function isApprovedForAll(address owner, address operator) external view returns (bool); + function isApprovedForAll( + address owner, + address operator + ) external view returns (bool); } interface IERC721Enumerable is IERC721 { @@ -153,7 +179,10 @@ interface IERC721Enumerable is IERC721 { * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ - function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); + function tokenOfOwnerByIndex( + address owner, + uint256 index + ) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. @@ -166,7 +195,9 @@ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ - function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { + function supportsInterface( + bytes4 interfaceId + ) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } @@ -239,7 +270,9 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { /** * @dev See {IERC165-supportsInterface}. */ - function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || @@ -249,15 +282,22 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { /** * @dev See {IERC721-balanceOf}. */ - function balanceOf(address owner) public view virtual override returns (uint256) { - require(owner != address(0), "ERC721: address zero is not a valid owner"); + function balanceOf( + address owner + ) public view virtual override returns (uint256) { + require( + owner != address(0), + "ERC721: address zero is not a valid owner" + ); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ - function ownerOf(uint256 tokenId) public view virtual override returns (address) { + function ownerOf( + uint256 tokenId + ) public view virtual override returns (address) { address owner = _ownerOf(tokenId); require(owner != address(0), "ERC721: invalid token ID"); return owner; @@ -280,11 +320,16 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { /** * @dev See {IERC721Metadata-tokenURI}. */ - function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { + function tokenURI( + uint256 tokenId + ) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); - return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; + return + bytes(baseURI).length > 0 + ? string(abi.encodePacked(baseURI, tokenId.toString())) + : ""; } /** @@ -314,7 +359,9 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { /** * @dev See {IERC721-getApproved}. */ - function getApproved(uint256 tokenId) public view virtual override returns (address) { + function getApproved( + uint256 tokenId + ) public view virtual override returns (address) { _requireMinted(tokenId); return _tokenApprovals[tokenId]; @@ -323,23 +370,36 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { /** * @dev See {IERC721-setApprovalForAll}. */ - function setApprovalForAll(address operator, bool approved) public virtual override { + function setApprovalForAll( + address operator, + bool approved + ) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ - function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { + function isApprovedForAll( + address owner, + address operator + ) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ - function transferFrom(address from, address to, uint256 tokenId) public virtual override { + function transferFrom( + address from, + address to, + uint256 tokenId + ) public virtual override { //solhint-disable-next-line max-line-length - require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved"); + require( + _isApprovedOrOwner(_msgSender(), tokenId), + "ERC721: caller is not token owner or approved" + ); _transfer(from, to, tokenId); } @@ -347,15 +407,27 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { /** * @dev See {IERC721-safeTransferFrom}. */ - function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { + function safeTransferFrom( + address from, + address to, + uint256 tokenId + ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ - function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override { - require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved"); + function safeTransferFrom( + address from, + address to, + uint256 tokenId, + bytes memory data + ) public virtual override { + require( + _isApprovedOrOwner(_msgSender(), tokenId), + "ERC721: caller is not token owner or approved" + ); _safeTransfer(from, to, tokenId, data); } @@ -377,9 +449,17 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * * Emits a {Transfer} event. */ - function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual { + function _safeTransfer( + address from, + address to, + uint256 tokenId, + bytes memory data + ) internal virtual { _transfer(from, to, tokenId); - require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer"); + require( + _checkOnERC721Received(from, to, tokenId, data), + "ERC721: transfer to non ERC721Receiver implementer" + ); } /** @@ -408,9 +488,14 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * * - `tokenId` must exist. */ - function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { + function _isApprovedOrOwner( + address spender, + uint256 tokenId + ) internal view virtual returns (bool) { address owner = ERC721.ownerOf(tokenId); - return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender); + return (spender == owner || + isApprovedForAll(owner, spender) || + getApproved(tokenId) == spender); } /** @@ -431,7 +516,11 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ - function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual { + function _safeMint( + address to, + uint256 tokenId, + bytes memory data + ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, data), @@ -520,14 +609,24 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * * Emits a {Transfer} event. */ - function _transfer(address from, address to, uint256 tokenId) internal virtual { - require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); + function _transfer( + address from, + address to, + uint256 tokenId + ) internal virtual { + require( + ERC721.ownerOf(tokenId) == from, + "ERC721: transfer from incorrect owner" + ); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId, 1); // Check that tokenId was not transferred by `_beforeTokenTransfer` hook - require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); + require( + ERC721.ownerOf(tokenId) == from, + "ERC721: transfer from incorrect owner" + ); // Clear approvals from the previous owner delete _tokenApprovals[tokenId]; @@ -563,7 +662,11 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * * Emits an {ApprovalForAll} event. */ - function _setApprovalForAll(address owner, address operator, bool approved) internal virtual { + function _setApprovalForAll( + address owner, + address operator, + bool approved + ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); @@ -593,11 +696,20 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { bytes memory data ) private returns (bool) { if (to.isContract()) { - try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) { + try + IERC721Receiver(to).onERC721Received( + _msgSender(), + from, + tokenId, + data + ) + returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { - revert("ERC721: transfer to non ERC721Receiver implementer"); + revert( + "ERC721: transfer to non ERC721Receiver implementer" + ); } else { /// @solidity memory-safe-assembly assembly { @@ -654,7 +766,12 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ - function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {} + function _afterTokenTransfer( + address from, + address to, + uint256 firstTokenId, + uint256 batchSize + ) internal virtual {} } abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { @@ -673,15 +790,25 @@ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { /** * @dev See {IERC165-supportsInterface}. */ - function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { - return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(IERC165, ERC721) returns (bool) { + return + interfaceId == type(IERC721Enumerable).interfaceId || + super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ - function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { - require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); + function tokenOfOwnerByIndex( + address owner, + uint256 index + ) public view virtual override returns (uint256) { + require( + index < ERC721.balanceOf(owner), + "ERC721Enumerable: owner index out of bounds" + ); return _ownedTokens[owner][index]; } @@ -695,8 +822,13 @@ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { /** * @dev See {IERC721Enumerable-tokenByIndex}. */ - function tokenByIndex(uint256 index) public view virtual override returns (uint256) { - require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); + function tokenByIndex( + uint256 index + ) public view virtual override returns (uint256) { + require( + index < ERC721Enumerable.totalSupply(), + "ERC721Enumerable: global index out of bounds" + ); return _allTokens[index]; } @@ -758,7 +890,10 @@ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ - function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { + function _removeTokenFromOwnerEnumeration( + address from, + uint256 tokenId + ) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). @@ -804,25 +939,19 @@ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { } } -abstract contract BibliotecaERC721 is ERC721, Ownable, ERC721Enumerable -{ +abstract contract BibliotecaERC721 is ERC721, Ownable, ERC721Enumerable { function _beforeTokenTransfer( address from, address to, uint256 firstTokenId, - uint256 batchSize) - internal - override(ERC721, ERC721Enumerable) - { + uint256 batchSize + ) internal override(ERC721, ERC721Enumerable) { super._beforeTokenTransfer(from, to, firstTokenId, batchSize); } - function supportsInterface(bytes4 interfaceId) - public - view - override(ERC721, ERC721Enumerable) - returns (bool) - { + function supportsInterface( + bytes4 interfaceId + ) public view override(ERC721, ERC721Enumerable) returns (bool) { return super.supportsInterface(interfaceId); } -} \ No newline at end of file +} diff --git a/contracts/ERC721/ERC721a.sol b/contracts/ERC721/ERC721a.sol index 6082fb8..63230bc 100644 --- a/contracts/ERC721/ERC721a.sol +++ b/contracts/ERC721/ERC721a.sol @@ -119,18 +119,30 @@ interface IERC721A { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ - event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); + event Transfer( + address indexed from, + address indexed to, + uint256 indexed tokenId + ); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ - event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); + event Approval( + address indexed owner, + address indexed approved, + uint256 indexed tokenId + ); /** * @dev Emitted when `owner` enables or disables * (`approved`) `operator` to manage all of its assets. */ - event ApprovalForAll(address indexed owner, address indexed operator, bool approved); + event ApprovalForAll( + address indexed owner, + address indexed operator, + bool approved + ); /** * @dev Returns the number of tokens in `owner`'s account. @@ -237,14 +249,19 @@ interface IERC721A { * * - `tokenId` must exist. */ - function getApproved(uint256 tokenId) external view returns (address operator); + function getApproved( + uint256 tokenId + ) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll}. */ - function isApprovedForAll(address owner, address operator) external view returns (bool); + function isApprovedForAll( + address owner, + address operator + ) external view returns (bool); // ============================================================= // IERC721Metadata @@ -276,7 +293,12 @@ interface IERC721A { * * See {_mintERC2309} for more details. */ - event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to); + event ConsecutiveTransfer( + uint256 indexed fromTokenId, + uint256 toTokenId, + address indexed from, + address indexed to + ); } /** @@ -473,7 +495,9 @@ contract ERC721A is IERC721A, Ownable { /** * @dev Returns the number of tokens in `owner`'s account. */ - function balanceOf(address owner) public view virtual override returns (uint256) { + function balanceOf( + address owner + ) public view virtual override returns (uint256) { if (owner == address(0)) revert BalanceQueryForZeroAddress(); return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY; } @@ -482,14 +506,18 @@ contract ERC721A is IERC721A, Ownable { * Returns the number of tokens minted by `owner`. */ function _numberMinted(address owner) internal view returns (uint256) { - return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY; + return + (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & + _BITMASK_ADDRESS_DATA_ENTRY; } /** * Returns the number of tokens burned by or on behalf of `owner`. */ function _numberBurned(address owner) internal view returns (uint256) { - return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY; + return + (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & + _BITMASK_ADDRESS_DATA_ENTRY; } /** @@ -510,7 +538,9 @@ contract ERC721A is IERC721A, Ownable { assembly { auxCasted := aux } - packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX); + packed = + (packed & _BITMASK_AUX_COMPLEMENT) | + (auxCasted << _BITPOS_AUX); _packedAddressData[owner] = packed; } @@ -526,7 +556,9 @@ contract ERC721A is IERC721A, Ownable { * * This function call must use less than 30000 gas. */ - function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { + function supportsInterface( + bytes4 interfaceId + ) public view virtual override returns (bool) { // The interface IDs are constants representing the first 4 bytes // of the XOR of all function selectors in the interface. // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165) @@ -558,11 +590,16 @@ contract ERC721A is IERC721A, Ownable { /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ - function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { + function tokenURI( + uint256 tokenId + ) public view virtual override returns (string memory) { if (!_exists(tokenId)) revert URIQueryForNonexistentToken(); string memory baseURI = _baseURI(); - return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : ''; + return + bytes(baseURI).length != 0 + ? string(abi.encodePacked(baseURI, _toString(tokenId))) + : ""; } /** @@ -571,7 +608,7 @@ contract ERC721A is IERC721A, Ownable { * by default, it can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { - return ''; + return ""; } // ============================================================= @@ -585,7 +622,9 @@ contract ERC721A is IERC721A, Ownable { * * - `tokenId` must exist. */ - function ownerOf(uint256 tokenId) public view virtual override returns (address) { + function ownerOf( + uint256 tokenId + ) public view virtual override returns (address) { return address(uint160(_packedOwnershipOf(tokenId))); } @@ -593,14 +632,18 @@ contract ERC721A is IERC721A, Ownable { * @dev Gas spent here starts off proportional to the maximum mint batch size. * It gradually moves to O(1) as tokens get transferred around over time. */ - function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) { + function _ownershipOf( + uint256 tokenId + ) internal view virtual returns (TokenOwnership memory) { return _unpackedOwnership(_packedOwnershipOf(tokenId)); } /** * @dev Returns the unpacked `TokenOwnership` struct at `index`. */ - function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) { + function _ownershipAt( + uint256 index + ) internal view virtual returns (TokenOwnership memory) { return _unpackedOwnership(_packedOwnerships[index]); } @@ -616,14 +659,17 @@ contract ERC721A is IERC721A, Ownable { /** * Returns the packed ownership data of `tokenId`. */ - function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) { + function _packedOwnershipOf( + uint256 tokenId + ) private view returns (uint256 packed) { if (_startTokenId() <= tokenId) { packed = _packedOwnerships[tokenId]; // If not burned. if (packed & _BITMASK_BURNED == 0) { // If the data at the starting slot does not exist, start the scan. if (packed == 0) { - if (tokenId >= _currentIndex) revert OwnerQueryForNonexistentToken(); + if (tokenId >= _currentIndex) + revert OwnerQueryForNonexistentToken(); // Invariant: // There will always be an initialized ownership slot // (i.e. `ownership.addr != address(0) && ownership.burned == false`) @@ -653,7 +699,9 @@ contract ERC721A is IERC721A, Ownable { /** * @dev Returns the unpacked `TokenOwnership` struct from `packed`. */ - function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) { + function _unpackedOwnership( + uint256 packed + ) private pure returns (TokenOwnership memory ownership) { ownership.addr = address(uint160(packed)); ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP); ownership.burned = packed & _BITMASK_BURNED != 0; @@ -663,19 +711,27 @@ contract ERC721A is IERC721A, Ownable { /** * @dev Packs ownership data into a single uint256. */ - function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) { + function _packOwnershipData( + address owner, + uint256 flags + ) private view returns (uint256 result) { assembly { // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean. owner := and(owner, _BITMASK_ADDRESS) // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`. - result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags)) + result := or( + owner, + or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags) + ) } } /** * @dev Returns the `nextInitialized` flag set if `quantity` equals 1. */ - function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) { + function _nextInitializedFlag( + uint256 quantity + ) private pure returns (uint256 result) { // For branchless setting of the `nextInitialized` flag. assembly { // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`. @@ -694,7 +750,10 @@ contract ERC721A is IERC721A, Ownable { * * - The caller must own the token or be an approved operator. */ - function approve(address to, uint256 tokenId) public payable virtual override { + function approve( + address to, + uint256 tokenId + ) public payable virtual override { _approve(to, tokenId, true); } @@ -705,7 +764,9 @@ contract ERC721A is IERC721A, Ownable { * * - `tokenId` must exist. */ - function getApproved(uint256 tokenId) public view virtual override returns (address) { + function getApproved( + uint256 tokenId + ) public view virtual override returns (address) { if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken(); return _tokenApprovals[tokenId].value; @@ -722,7 +783,10 @@ contract ERC721A is IERC721A, Ownable { * * Emits an {ApprovalForAll} event. */ - function setApprovalForAll(address operator, bool approved) public virtual override { + function setApprovalForAll( + address operator, + bool approved + ) public virtual override { _operatorApprovals[_msgSenderERC721A()][operator] = approved; emit ApprovalForAll(_msgSenderERC721A(), operator, approved); } @@ -732,7 +796,10 @@ contract ERC721A is IERC721A, Ownable { * * See {setApprovalForAll}. */ - function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { + function isApprovedForAll( + address owner, + address operator + ) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } @@ -771,7 +838,9 @@ contract ERC721A is IERC721A, Ownable { /** * @dev Returns the storage slot and value for the approved address of `tokenId`. */ - function _getApprovedSlotAndAddress(uint256 tokenId) + function _getApprovedSlotAndAddress( + uint256 tokenId + ) private view returns (uint256 approvedAddressSlot, address approvedAddress) @@ -808,13 +877,24 @@ contract ERC721A is IERC721A, Ownable { ) public payable virtual override { uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId); - if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner(); + if (address(uint160(prevOwnershipPacked)) != from) + revert TransferFromIncorrectOwner(); - (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId); + ( + uint256 approvedAddressSlot, + address approvedAddress + ) = _getApprovedSlotAndAddress(tokenId); // The nested ifs save around 20+ gas over a compound boolean condition. - if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A())) - if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved(); + if ( + !_isSenderApprovedOrOwner( + approvedAddress, + from, + _msgSenderERC721A() + ) + ) + if (!isApprovedForAll(from, _msgSenderERC721A())) + revert TransferCallerNotOwnerNorApproved(); if (to == address(0)) revert TransferToZeroAddress(); @@ -843,7 +923,8 @@ contract ERC721A is IERC721A, Ownable { // - `nextInitialized` to `true`. _packedOwnerships[tokenId] = _packOwnershipData( to, - _BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked) + _BITMASK_NEXT_INITIALIZED | + _nextExtraData(from, to, prevOwnershipPacked) ); // If the next slot may not have been initialized (i.e. `nextInitialized == false`) . @@ -872,7 +953,7 @@ contract ERC721A is IERC721A, Ownable { address to, uint256 tokenId ) public payable virtual override { - safeTransferFrom(from, to, tokenId, ''); + safeTransferFrom(from, to, tokenId, ""); } /** @@ -965,10 +1046,17 @@ contract ERC721A is IERC721A, Ownable { uint256 tokenId, bytes memory _data ) private returns (bool) { - try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns ( - bytes4 retval - ) { - return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector; + try + ERC721A__IERC721Receiver(to).onERC721Received( + _msgSenderERC721A(), + from, + tokenId, + _data + ) + returns (bytes4 retval) { + return + retval == + ERC721A__IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); @@ -1009,7 +1097,9 @@ contract ERC721A is IERC721A, Ownable { // - `numberMinted += quantity`. // // We can directly add to the `balance` and `numberMinted`. - _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1); + _packedAddressData[to] += + quantity * + ((1 << _BITPOS_NUMBER_MINTED) | 1); // Updates: // - `address` to the owner. @@ -1018,7 +1108,8 @@ contract ERC721A is IERC721A, Ownable { // - `nextInitialized` to `quantity == 1`. _packedOwnerships[startTokenId] = _packOwnershipData( to, - _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0) + _nextInitializedFlag(quantity) | + _nextExtraData(address(0), to, 0) ); uint256 toMasked; @@ -1085,7 +1176,8 @@ contract ERC721A is IERC721A, Ownable { uint256 startTokenId = _currentIndex; if (to == address(0)) revert MintToZeroAddress(); if (quantity == 0) revert MintZeroQuantity(); - if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit(); + if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) + revert MintERC2309QuantityExceedsLimit(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); @@ -1096,7 +1188,9 @@ contract ERC721A is IERC721A, Ownable { // - `numberMinted += quantity`. // // We can directly add to the `balance` and `numberMinted`. - _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1); + _packedAddressData[to] += + quantity * + ((1 << _BITPOS_NUMBER_MINTED) | 1); // Updates: // - `address` to the owner. @@ -1105,10 +1199,16 @@ contract ERC721A is IERC721A, Ownable { // - `nextInitialized` to `quantity == 1`. _packedOwnerships[startTokenId] = _packOwnershipData( to, - _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0) + _nextInitializedFlag(quantity) | + _nextExtraData(address(0), to, 0) ); - emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to); + emit ConsecutiveTransfer( + startTokenId, + startTokenId + quantity - 1, + address(0), + to + ); _currentIndex = startTokenId + quantity; } @@ -1140,7 +1240,14 @@ contract ERC721A is IERC721A, Ownable { uint256 end = _currentIndex; uint256 index = end - quantity; do { - if (!_checkContractOnERC721Received(address(0), to, index++, _data)) { + if ( + !_checkContractOnERC721Received( + address(0), + to, + index++, + _data + ) + ) { revert TransferToNonERC721ReceiverImplementer(); } } while (index < end); @@ -1154,7 +1261,7 @@ contract ERC721A is IERC721A, Ownable { * @dev Equivalent to `_safeMint(to, quantity, '')`. */ function _safeMint(address to, uint256 quantity) internal virtual { - _safeMint(to, quantity, ''); + _safeMint(to, quantity, ""); } // ============================================================= @@ -1224,12 +1331,22 @@ contract ERC721A is IERC721A, Ownable { address from = address(uint160(prevOwnershipPacked)); - (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId); + ( + uint256 approvedAddressSlot, + address approvedAddress + ) = _getApprovedSlotAndAddress(tokenId); if (approvalCheck) { // The nested ifs save around 20+ gas over a compound boolean condition. - if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A())) - if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved(); + if ( + !_isSenderApprovedOrOwner( + approvedAddress, + from, + _msgSenderERC721A() + ) + ) + if (!isApprovedForAll(from, _msgSenderERC721A())) + revert TransferCallerNotOwnerNorApproved(); } _beforeTokenTransfers(from, address(0), tokenId, 1); @@ -1261,7 +1378,8 @@ contract ERC721A is IERC721A, Ownable { // - `nextInitialized` to `true`. _packedOwnerships[tokenId] = _packOwnershipData( from, - (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked) + (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | + _nextExtraData(from, address(0), prevOwnershipPacked) ); // If the next slot may not have been initialized (i.e. `nextInitialized == false`) . @@ -1302,7 +1420,9 @@ contract ERC721A is IERC721A, Ownable { assembly { extraDataCasted := extraData } - packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA); + packed = + (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | + (extraDataCasted << _BITPOS_EXTRA_DATA); _packedOwnerships[index] = packed; } @@ -1355,7 +1475,9 @@ contract ERC721A is IERC721A, Ownable { /** * @dev Converts a uint256 to its ASCII string decimal representation. */ - function _toString(uint256 value) internal pure virtual returns (string memory str) { + function _toString( + uint256 value + ) internal pure virtual returns (string memory str) { assembly { // The maximum value of a uint256 contains 78 digits (1 byte per digit), but // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned. @@ -1393,4 +1515,4 @@ contract ERC721A is IERC721A, Ownable { mstore(str, length) } } -} \ No newline at end of file +} diff --git a/contracts/ERC721/ERC721aCollection.sol b/contracts/ERC721/ERC721aCollection.sol index fd2a73b..55f7312 100644 --- a/contracts/ERC721/ERC721aCollection.sol +++ b/contracts/ERC721/ERC721aCollection.sol @@ -5,8 +5,7 @@ pragma solidity ^0.8.0; import "./ERC721a.sol"; -contract ERC721aCollection is ERC721A -{ +contract ERC721aCollection is ERC721A { string BASE_URI; uint MAX_SUPPLY; uint PRICE; @@ -19,8 +18,7 @@ contract ERC721aCollection is ERC721A string memory base_uri, uint max_supply, uint _price - ) ERC721A(name, symbol) - { + ) ERC721A(name, symbol) { BASE_URI = base_uri; MAX_SUPPLY = max_supply; PRICE = _price; @@ -28,17 +26,15 @@ contract ERC721aCollection is ERC721A // Public functions - function mint(address account, uint amount) public payable - { - require(msg.value == price()*amount, "Invalid payment"); + function mint(address account, uint amount) public payable { + require(msg.value == price() * amount, "Invalid payment"); require(totalSupply() + amount < maxSupply(), "Max supply reached"); _safeMint(account, amount); } // Owner functions - function withdraw() public onlyOwner - { + function withdraw() public onlyOwner { (bool success, ) = msg.sender.call{value: address(this).balance}(""); require(success, "Transfer failed."); } @@ -56,4 +52,4 @@ contract ERC721aCollection is ERC721A function price() public view virtual returns (uint) { return PRICE; } -} \ No newline at end of file +} diff --git a/contracts/ERC721/OpenZeppelinNFTCollection.sol b/contracts/ERC721/OpenZeppelinNFTCollection.sol index 9738e7f..3d4b081 100644 --- a/contracts/ERC721/OpenZeppelinNFTCollection.sol +++ b/contracts/ERC721/OpenZeppelinNFTCollection.sol @@ -22,8 +22,7 @@ contract OpenZeppelinNFTCollection is BibliotecaERC721 { string memory base_uri, uint max_supply, uint _price - ) ERC721(name, symbol) - { + ) ERC721(name, symbol) { BASE_URI = base_uri; MAX_SUPPLY = max_supply; PRICE = _price; @@ -31,12 +30,10 @@ contract OpenZeppelinNFTCollection is BibliotecaERC721 { // Public functions - function mint(address account, uint amount) public payable - { - require(msg.value == price()*amount, "Invalid payment"); + function mint(address account, uint amount) public payable { + require(msg.value == price() * amount, "Invalid payment"); require(totalSupply() + amount < maxSupply(), "Max supply reached"); - for(uint i; i= amount, "Address: insufficient balance"); + require( + address(this).balance >= amount, + "Address: insufficient balance" + ); (bool success, ) = recipient.call{value: amount}(""); - require(success, "Address: unable to send value, recipient may have reverted"); + require( + success, + "Address: unable to send value, recipient may have reverted" + ); } /** @@ -86,8 +92,17 @@ library Address { * * _Available since v3.1._ */ - function functionCall(address target, bytes memory data) internal returns (bytes memory) { - return functionCallWithValue(target, data, 0, "Address: low-level call failed"); + function functionCall( + address target, + bytes memory data + ) internal returns (bytes memory) { + return + functionCallWithValue( + target, + data, + 0, + "Address: low-level call failed" + ); } /** @@ -115,8 +130,18 @@ library Address { * * _Available since v3.1._ */ - function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { - return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + function functionCallWithValue( + address target, + bytes memory data, + uint256 value + ) internal returns (bytes memory) { + return + functionCallWithValue( + target, + data, + value, + "Address: low-level call with value failed" + ); } /** @@ -131,9 +156,20 @@ library Address { uint256 value, string memory errorMessage ) internal returns (bytes memory) { - require(address(this).balance >= value, "Address: insufficient balance for call"); - (bool success, bytes memory returndata) = target.call{value: value}(data); - return verifyCallResultFromTarget(target, success, returndata, errorMessage); + require( + address(this).balance >= value, + "Address: insufficient balance for call" + ); + (bool success, bytes memory returndata) = target.call{value: value}( + data + ); + return + verifyCallResultFromTarget( + target, + success, + returndata, + errorMessage + ); } /** @@ -142,8 +178,16 @@ library Address { * * _Available since v3.3._ */ - function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { - return functionStaticCall(target, data, "Address: low-level static call failed"); + function functionStaticCall( + address target, + bytes memory data + ) internal view returns (bytes memory) { + return + functionStaticCall( + target, + data, + "Address: low-level static call failed" + ); } /** @@ -158,7 +202,13 @@ library Address { string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); - return verifyCallResultFromTarget(target, success, returndata, errorMessage); + return + verifyCallResultFromTarget( + target, + success, + returndata, + errorMessage + ); } /** @@ -167,8 +217,16 @@ library Address { * * _Available since v3.4._ */ - function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { - return functionDelegateCall(target, data, "Address: low-level delegate call failed"); + function functionDelegateCall( + address target, + bytes memory data + ) internal returns (bytes memory) { + return + functionDelegateCall( + target, + data, + "Address: low-level delegate call failed" + ); } /** @@ -183,7 +241,13 @@ library Address { string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); - return verifyCallResultFromTarget(target, success, returndata, errorMessage); + return + verifyCallResultFromTarget( + target, + success, + returndata, + errorMessage + ); } /** @@ -228,7 +292,10 @@ library Address { } } - function _revert(bytes memory returndata, string memory errorMessage) private pure { + function _revert( + bytes memory returndata, + string memory errorMessage + ) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly @@ -241,4 +308,4 @@ library Address { revert(errorMessage); } } -} \ No newline at end of file +} diff --git a/contracts/common/Context.sol b/contracts/common/Context.sol index 8f217c4..d5bb226 100644 --- a/contracts/common/Context.sol +++ b/contracts/common/Context.sol @@ -11,4 +11,4 @@ abstract contract Context { function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } -} \ No newline at end of file +} diff --git a/contracts/common/Counters.sol b/contracts/common/Counters.sol index e05b63f..983dd16 100644 --- a/contracts/common/Counters.sol +++ b/contracts/common/Counters.sol @@ -32,4 +32,4 @@ library Counters { function reset(Counter storage counter) internal { counter._value = 0; } -} \ No newline at end of file +} diff --git a/contracts/common/Ownable.sol b/contracts/common/Ownable.sol index 2fff37f..136631e 100644 --- a/contracts/common/Ownable.sol +++ b/contracts/common/Ownable.sol @@ -8,7 +8,10 @@ import "./Context.sol"; abstract contract Ownable is Context { address private _owner; - event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); constructor() { _transferOwnership(_msgSender()); @@ -32,7 +35,10 @@ abstract contract Ownable is Context { } function transferOwnership(address newOwner) public virtual onlyOwner { - require(newOwner != address(0), "Ownable: new owner is the zero address"); + require( + newOwner != address(0), + "Ownable: new owner is the zero address" + ); _transferOwnership(newOwner); } @@ -41,4 +47,4 @@ abstract contract Ownable is Context { _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } -} \ No newline at end of file +} diff --git a/contracts/common/Strings.sol b/contracts/common/Strings.sol index 3e9e647..f19d7ae 100644 --- a/contracts/common/Strings.sol +++ b/contracts/common/Strings.sol @@ -49,7 +49,11 @@ library Math { * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ - function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { + function mulDiv( + uint256 x, + uint256 y, + uint256 denominator + ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 @@ -130,7 +134,12 @@ library Math { /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ - function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { + function mulDiv( + uint256 x, + uint256 y, + uint256 denominator, + Rounding rounding + ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; @@ -179,10 +188,15 @@ library Math { /** * @notice Calculates sqrt(a), following the selected rounding direction. */ - function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { + function sqrt( + uint256 a, + Rounding rounding + ) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); - return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); + return + result + + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } @@ -232,10 +246,15 @@ library Math { * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ - function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { + function log2( + uint256 value, + Rounding rounding + ) internal pure returns (uint256) { unchecked { uint256 result = log2(value); - return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); + return + result + + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } @@ -281,10 +300,15 @@ library Math { * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ - function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { + function log10( + uint256 value, + Rounding rounding + ) internal pure returns (uint256) { unchecked { uint256 result = log10(value); - return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); + return + result + + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } @@ -324,10 +348,15 @@ library Math { * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ - function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { + function log256( + uint256 value, + Rounding rounding + ) internal pure returns (uint256) { unchecked { uint256 result = log256(value); - return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); + return + result + + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } } @@ -404,7 +433,13 @@ library Strings { * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { - return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); + return + string( + abi.encodePacked( + value < 0 ? "-" : "", + toString(SignedMath.abs(value)) + ) + ); } /** @@ -419,7 +454,10 @@ library Strings { /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ - function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { + function toHexString( + uint256 value, + uint256 length + ) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; @@ -441,7 +479,10 @@ library Strings { /** * @dev Returns true if the two strings are equal. */ - function equal(string memory a, string memory b) internal pure returns (bool) { + function equal( + string memory a, + string memory b + ) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } -} \ No newline at end of file +} diff --git a/contracts/examples/ERC20/MyBalancerFeeToken.sol b/contracts/examples/ERC20/MyBalancerFeeToken.sol index 2854967..6cbd30d 100644 --- a/contracts/examples/ERC20/MyBalancerFeeToken.sol +++ b/contracts/examples/ERC20/MyBalancerFeeToken.sol @@ -3,13 +3,16 @@ pragma solidity 0.8.17; import "../../ERC20/BalancerV2FeeToken.sol"; -contract MyBalancerFeeToken is BalancerV2FeeToken -{ - constructor() BalancerV2FeeToken( - "My Token", "MTKN", // Name and Symbol - 1_000_000_000 ether, // 1 billion supply - 100, 200, 50, // Fees: 2% buy 1% sell 0.5% P2P - msg.sender) // Fee Receiver - { - } -} \ No newline at end of file +contract MyBalancerFeeToken is BalancerV2FeeToken { + constructor() + BalancerV2FeeToken( + "My Token", + "MTKN", // Name and Symbol + 1_000_000_000 ether, // 1 billion supply + 100, + 200, + 50, // Fees: 2% buy 1% sell 0.5% P2P + msg.sender + ) // Fee Receiver + {} +} diff --git a/contracts/examples/ERC20/MyUniswapV2AutoSwapToken.sol b/contracts/examples/ERC20/MyUniswapV2AutoSwapToken.sol index 4fbac6c..6b8d5b9 100644 --- a/contracts/examples/ERC20/MyUniswapV2AutoSwapToken.sol +++ b/contracts/examples/ERC20/MyUniswapV2AutoSwapToken.sol @@ -3,16 +3,19 @@ pragma solidity 0.8.17; import "../../ERC20/UniswapV2AutoSwapToken.sol"; -contract MyUniswapV2AutoSwapToken is UniswapV2AutoSwapToken -{ - constructor() UniswapV2AutoSwapToken( - "My Token", "MTKN", // Name and Symbol - 1_000_000_000 ether, // 1 billion supply - 100, 200, 50, // Fees: 1% buy 2% sell 0.5% P2P - msg.sender, // AutoSwap Receiver - 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, // Router Address: Uniswap V2 - 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, // Base Token Address: USDC - 100) // 1% in tokens before swap percent - { - } -} \ No newline at end of file +contract MyUniswapV2AutoSwapToken is UniswapV2AutoSwapToken { + constructor() + UniswapV2AutoSwapToken( + "My Token", + "MTKN", // Name and Symbol + 1_000_000_000 ether, // 1 billion supply + 100, + 200, + 50, // Fees: 1% buy 2% sell 0.5% P2P + msg.sender, // AutoSwap Receiver + 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, // Router Address: Uniswap V2 + 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, // Base Token Address: USDC + 100 + ) // 1% in tokens before swap percent + {} +} diff --git a/contracts/examples/ERC20/MyUniswapV2FeeToken.sol b/contracts/examples/ERC20/MyUniswapV2FeeToken.sol index d3b8b9a..0465e9c 100644 --- a/contracts/examples/ERC20/MyUniswapV2FeeToken.sol +++ b/contracts/examples/ERC20/MyUniswapV2FeeToken.sol @@ -3,15 +3,18 @@ pragma solidity 0.8.17; import "../../ERC20/UniswapV2FeeToken.sol"; -contract MyUniswapV2FeeToken is UniswapV2FeeToken -{ - constructor() UniswapV2FeeToken( - "My Token", "MTKN", // Name and Symbol - 1_000_000_000 ether, // 1 billion supply - 100, 200, 50, // Fees: 1% buy 2% sell 0.5% P2P - msg.sender, // Fee Receiver - 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, // Router Address: Uniswap V2 - 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48) // Base Token Address: USDC - { - } -} \ No newline at end of file +contract MyUniswapV2FeeToken is UniswapV2FeeToken { + constructor() + UniswapV2FeeToken( + "My Token", + "MTKN", // Name and Symbol + 1_000_000_000 ether, // 1 billion supply + 100, + 200, + 50, // Fees: 1% buy 2% sell 0.5% P2P + msg.sender, // Fee Receiver + 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, // Router Address: Uniswap V2 + 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 + ) // Base Token Address: USDC + {} +} diff --git a/contracts/examples/ERC20/MyUniswapV3FeeToken.sol b/contracts/examples/ERC20/MyUniswapV3FeeToken.sol index edd7225..7941070 100644 --- a/contracts/examples/ERC20/MyUniswapV3FeeToken.sol +++ b/contracts/examples/ERC20/MyUniswapV3FeeToken.sol @@ -3,15 +3,17 @@ pragma solidity 0.8.17; import "../../ERC20/UniswapV3FeeToken.sol"; -contract MyUniswapV3FeeToken is UniswapV3FeeToken -{ - constructor() UniswapV3FeeToken( - "My Token", "MTKN", // Name and Symbol - 1_000_000_000 ether, // 1 billion supply - 100, 200, // Fees: 1% buy 2% P2P - msg.sender, // Vault Address - 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, // Base token: WETH - 1000) // Initial rate: 1 WETH = 1000 tokens - { - } -} \ No newline at end of file +contract MyUniswapV3FeeToken is UniswapV3FeeToken { + constructor() + UniswapV3FeeToken( + "My Token", + "MTKN", // Name and Symbol + 1_000_000_000 ether, // 1 billion supply + 100, + 200, // Fees: 1% buy 2% P2P + msg.sender, // Vault Address + 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, // Base token: WETH + 1000 + ) // Initial rate: 1 WETH = 1000 tokens + {} +} diff --git a/contracts/examples/ERC721/MyERC721aCollection.sol b/contracts/examples/ERC721/MyERC721aCollection.sol index e591971..dbddacc 100644 --- a/contracts/examples/ERC721/MyERC721aCollection.sol +++ b/contracts/examples/ERC721/MyERC721aCollection.sol @@ -3,13 +3,14 @@ pragma solidity 0.8.17; import "../../ERC721/ERC721aCollection.sol"; -contract MyERC721aCollection is ERC721aCollection -{ - constructor() ERC721aCollection( - "My NFT Collection", "MNFT", // Name and Symbol - "https://raw.githubusercontent.com/FilosofiaCodigo/nft-collection-api/master/metadata/", // Base Metadata URI - 10_000, // 10,000 max supply - 0.01 ether) // 0.01 eth mint price - { - } -} \ No newline at end of file +contract MyERC721aCollection is ERC721aCollection { + constructor() + ERC721aCollection( + "My NFT Collection", + "MNFT", // Name and Symbol + "https://raw.githubusercontent.com/FilosofiaCodigo/nft-collection-api/master/metadata/", // Base Metadata URI + 10_000, // 10,000 max supply + 0.01 ether + ) // 0.01 eth mint price + {} +} diff --git a/contracts/examples/ERC721/MyOpenZeppelinNFTCollection.sol b/contracts/examples/ERC721/MyOpenZeppelinNFTCollection.sol index 752f929..75b9d91 100644 --- a/contracts/examples/ERC721/MyOpenZeppelinNFTCollection.sol +++ b/contracts/examples/ERC721/MyOpenZeppelinNFTCollection.sol @@ -3,13 +3,14 @@ pragma solidity 0.8.17; import "../../ERC721/OpenZeppelinNFTCollection.sol"; -contract MyOpenZeppelinNFTCollection is OpenZeppelinNFTCollection -{ - constructor() OpenZeppelinNFTCollection( - "My NFT Collection", "MNFT", // Name and Symbol - "https://raw.githubusercontent.com/FilosofiaCodigo/nft-collection-api/master/metadata/", // Base Metadata URI - 10_000, // 10,000 max supply - 0.01 ether) // 0.01 eth mint price - { - } -} \ No newline at end of file +contract MyOpenZeppelinNFTCollection is OpenZeppelinNFTCollection { + constructor() + OpenZeppelinNFTCollection( + "My NFT Collection", + "MNFT", // Name and Symbol + "https://raw.githubusercontent.com/FilosofiaCodigo/nft-collection-api/master/metadata/", // Base Metadata URI + 10_000, // 10,000 max supply + 0.01 ether + ) // 0.01 eth mint price + {} +} diff --git a/package-lock.json b/package-lock.json index e7bb669..14c1c77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4459,11 +4459,57 @@ "dev": true }, "prettier": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", - "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.3.tgz", + "integrity": "sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==", "dev": true }, + "prettier-plugin-solidity": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/prettier-plugin-solidity/-/prettier-plugin-solidity-1.1.1.tgz", + "integrity": "sha512-uD24KO26tAHF+zMN2nt1OUzfknzza5AgxjogQQrMLZc7j8xiQrDoNWNeOlfFC0YLTwo12CLD10b9niLyP6AqXg==", + "dev": true, + "requires": { + "@solidity-parser/parser": "^0.14.5", + "semver": "^7.3.8", + "solidity-comments-extractor": "^0.0.7" + }, + "dependencies": { + "@solidity-parser/parser": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.14.5.tgz", + "integrity": "sha512-6dKnHZn7fg/iQATVEzqyUOyEidbn05q7YA2mQ9hC0MMXhhV3/JrsxmFSYZAcr7j1yUP700LLhTruvJ3MiQmjJg==", + "dev": true, + "requires": { + "antlr4ts": "^0.5.0-alpha.4" + } + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -5049,6 +5095,12 @@ "resolved": "https://registry.npmjs.org/solidity-ast/-/solidity-ast-0.4.45.tgz", "integrity": "sha512-N6uqfaDulVZqjpjru+KvMLjV89M3hesyr/1/t8nkjohRagFSDmDxZvb9viKV98pdwpMzs61Nt2JAApgh0fkL0g==" }, + "solidity-comments-extractor": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/solidity-comments-extractor/-/solidity-comments-extractor-0.0.7.tgz", + "integrity": "sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw==", + "dev": true + }, "solidity-coverage": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/solidity-coverage/-/solidity-coverage-0.8.2.tgz", diff --git a/package.json b/package.json index c40f158..998080a 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "ethers": "^5.7.1", "hardhat": "^2.11.2", "hardhat-gas-reporter": "^1.0.9", + "prettier": "^2.8.3", + "prettier-plugin-solidity": "^1.1.1", "solidity-coverage": "^0.8.2", "typechain": "^8.1.0" },