There is a posbility to add a function to my contract that check price impact and if it <7% block sale?
like for example if token went up by 20% to new ath and now holders want to sell, they can sell until its down 7% from ATH, now the sells would stop until we break new ath and can sell again.
You can get the reserves of the liquidity token to determine the current price.
You can do this on all transfers to keep track of the highest price.
Keep in mind that people can use flashloans to manipulate the price/ATH
Let's say you have a token with liquidity. Someone could borrow lots of money from a flash loan provider, then buy your token to set a new ATH and then sell it again. Now there is a new ATH even if the price never actually changed for more than 1 block.
understood. thank you very much for the info and help !!
Can you please maybe give me some info about the "reserves of the liquidity token to determine the current price.
You can do this on all transfers to keep track of the highest price."
well first of all you need the address of the liquidity pair. ( I will use pancakeswap as example) To get it you can use the function getpair in the pancakeswap factory. You can do that in your contract.
After you got the liquidity pair address you can call the function getReserves() to get reserve of token0 and token1. based on which token is which you divide the bnb with the token (bnb/token = price per token in bnb).
If this value is higher than the last stored ATH you can set it to the new ATH.
uint ATH = 0;
address factory = FACTORY_ADDRESS;
address pair = factory.getPair(wbnb, address(this));
function checkATH() private {
//tokens may be different
//wbnb, token
(uint res0, uint res1) = pair.getReserves();
//solidity can't handle decimals
res0 *= 1e18;
if(res0 / res1 > ATH)
ATH = res0 / res1;
}
Keep in mind that you will need interfaces etc.
If this helped you it would be nice if you can mark the post as solution.