From 3a0ab9129102727ac1059a056bdd869c03a0a8cd Mon Sep 17 00:00:00 2001 From: turupawn Date: Mon, 26 Sep 2022 16:14:11 -0600 Subject: [PATCH] docs --- contracts/ERC20/UniswapV2AutoSwapToken.sol | 4 +- contracts/ERC20/UniswapV2FeeToken.sol | 50 ++++++++++++++++------ contracts/ERC20/UniswapV2Interfaces.sol | 1 + docs/BalancerFeeToken.md | 0 docs/UniswapV2AutoSwapToken.md | 0 docs/UniswapV2FeeToken.md | 22 ++++++++++ docs/UniswapV3FeeToken.md | 0 7 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 docs/BalancerFeeToken.md create mode 100644 docs/UniswapV2AutoSwapToken.md create mode 100644 docs/UniswapV2FeeToken.md create mode 100644 docs/UniswapV3FeeToken.md diff --git a/contracts/ERC20/UniswapV2AutoSwapToken.sol b/contracts/ERC20/UniswapV2AutoSwapToken.sol index 79ee5fb..7d0fcae 100644 --- a/contracts/ERC20/UniswapV2AutoSwapToken.sol +++ b/contracts/ERC20/UniswapV2AutoSwapToken.sol @@ -33,9 +33,9 @@ abstract contract UniswapV2AutoSwapToken is UniswapV2FeeToken modifier lockTheSwap() { lastFeeActive = isFeeActive; - setFeeActive(false); + _setFeeActive(false); _; - setFeeActive(lastFeeActive); + _setFeeActive(lastFeeActive); } function swap() private lockTheSwap { diff --git a/contracts/ERC20/UniswapV2FeeToken.sol b/contracts/ERC20/UniswapV2FeeToken.sol index bd2cc31..abb4d64 100644 --- a/contracts/ERC20/UniswapV2FeeToken.sol +++ b/contracts/ERC20/UniswapV2FeeToken.sol @@ -9,18 +9,18 @@ import "./UniswapV2Interfaces.sol"; abstract contract UniswapV2FeeToken is ERC20 { mapping(address => bool) public isTaxless; - address public tokenVaultAddress; + address public feeReceiverAddress; bool public isFeeActive; - address public pair; uint[] public fees; uint public feeDecimals = 2; + address public pair; ISwapRouter router; IERC20 baseToken; constructor(string memory name, string memory symbol, uint totalSupply_, - address tokenVaultAddress_, + address feeReceiverAddress_, uint buyFee, uint sellFee, uint p2pFee, address routerAddress, address baseTokenAddress) ERC20(name, symbol, totalSupply_) @@ -29,11 +29,11 @@ abstract contract UniswapV2FeeToken is ERC20 pair = ISwapFactory(router.factory()).createPair(address(this), baseTokenAddress); baseToken = IERC20(baseTokenAddress); - tokenVaultAddress = tokenVaultAddress_; + feeReceiverAddress = feeReceiverAddress_; isTaxless[msg.sender] = true; isTaxless[address(this)] = true; - isTaxless[tokenVaultAddress] = true; + isTaxless[feeReceiverAddress] = true; isTaxless[address(0)] = true; fees[0] = buyFee; @@ -47,7 +47,8 @@ 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; @@ -58,18 +59,43 @@ abstract contract UniswapV2FeeToken is ERC20 amount -= feesCollected; _balances[from] -= feesCollected; - _balances[tokenVaultAddress] += feesCollected; + _balances[feeReceiverAddress] += feesCollected; - emit Transfer(from, tokenVaultAddress, amount); + emit Transfer(from, feeReceiverAddress, amount); super._transfer(from, to, amount); } - function setTaxless(address account, bool value) external onlyOwner { - isTaxless[account] = value; + function _setTaxless(address account, bool isTaxless_) internal + { + isTaxless[account] = isTaxless_; + } + + function _setFeeReceiverAddress(address feeReceiverAddress_) internal + { + feeReceiverAddress = feeReceiverAddress_; + } + + function _setFeeActive(bool isFeeActive_) internal + { + isFeeActive = isFeeActive_; + } + + 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)); + } } - function setFeeActive(bool value) public onlyOwner { - isFeeActive = value; + function _setFees(uint buyFee, uint sellFee, uint p2pFee) internal + { + fees[0] = buyFee; + fees[1] = sellFee; + fees[2] = p2pFee; } } \ No newline at end of file diff --git a/contracts/ERC20/UniswapV2Interfaces.sol b/contracts/ERC20/UniswapV2Interfaces.sol index e99b704..1252db0 100644 --- a/contracts/ERC20/UniswapV2Interfaces.sol +++ b/contracts/ERC20/UniswapV2Interfaces.sol @@ -16,5 +16,6 @@ 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 diff --git a/docs/BalancerFeeToken.md b/docs/BalancerFeeToken.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/UniswapV2AutoSwapToken.md b/docs/UniswapV2AutoSwapToken.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/UniswapV2FeeToken.md b/docs/UniswapV2FeeToken.md new file mode 100644 index 0000000..4f84380 --- /dev/null +++ b/docs/UniswapV2FeeToken.md @@ -0,0 +1,22 @@ +# UniswapV2FeeToken + +## Technical contract overview + +The UniswapV2FeeToken is a type of token very common in DeFi. It collects fees depending on the transaction type (Sell, Buy or P2P peer to peer). Fees are sent to a `feeReceiverAddress`. In the constructor a `router` and `baseToken` is set in order to create a uniswap `pair`. The `pair` helps us detecting wheter a transaction is Sell, Buy or P2P. + +## Constructing a UniswapV2FeeToken contract + +ToDo. + +## API + +* **_setTaxless**(address account, bool isTaxless_) internal + * Add a Fee exempt address. +* **_setFeeReceiverAddress**(address feeReceiverAddress_) internal + * Address that will receive the token Fees collected. +* **_setFeeActive**(bool isFeeActive_) internal + * Set wheter or not fees are being collected. +* **_setPair**(address router_, address baseToken_)** internal + * Change the main pair address by passing the router and the base token as parameter. Creates a new pair in case it wasn't created. After this function is called the fees will be collected in this pair. +* **_setFees**(uint buyFeePercentage, uint sellFeePercentage, uint p2pFeePercentage)** internal + * Buy and sell fees are collected when interacting with the pair. P2P fees are collected when interacting with other address than the pair. \ No newline at end of file diff --git a/docs/UniswapV3FeeToken.md b/docs/UniswapV3FeeToken.md new file mode 100644 index 0000000..e69de29