I have a simple code to calculates the needed token amount for the cases when I buy a token with 5% slippage. I just simply check how many tokens could I receive for the current price, get its 95% and use the amount for the swapExactETHForTokens
function's amountOutMin
. My question is that should I pay attention for the decimal of the token? Is there any scenario when I have to use it to calculate the correct token number which fits to the slippage?
This is how I do it now. I don't use the decimal at all.
def get_slippage(token_price, budget, slippage_percentage):
original_amount = round(budget / token_price)
one_percent = original_amount / 100
token_amount_slippage_5p = round(one_percent * slippage_percentage)
return token_amount_slippage_5p