Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Turupawn committed Sep 26, 2022
1 parent bf59f4d commit 3a0ab91
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 14 deletions.
4 changes: 2 additions & 2 deletions contracts/ERC20/UniswapV2AutoSwapToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
50 changes: 38 additions & 12 deletions contracts/ERC20/UniswapV2FeeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions contracts/ERC20/UniswapV2Interfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Empty file added docs/BalancerFeeToken.md
Empty file.
Empty file added docs/UniswapV2AutoSwapToken.md
Empty file.
22 changes: 22 additions & 0 deletions docs/UniswapV2FeeToken.md
Original file line number Diff line number Diff line change
@@ -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.
Empty file added docs/UniswapV3FeeToken.md
Empty file.

0 comments on commit 3a0ab91

Please sign in to comment.