Build a solidity function that calculates token payouts for ico.
Budget: $30 – $250 USD
Hello,
I need a function that precicely can calculate the users totalpayouts based on 3 variables.
1: The max tokens for sale.
2: The total raised amount needed for the project.
3: Amount the users would want to purchase for.
4: Token decimal of the token we would want to purchase.
I have previously userd this function to calculate users rewards:
function calcTokenRewards(
uint256 allocatedTokensForPresale, //The amount of tokens that is being sold.
uint256 decimals //The amount of decimal the token have.
uint256 maxcap, //The amount that all the tokens combined can be sold for.
uint256 amountToConvertInBNB, //The amount of money we would spend
) private pure returns (uint256) {
uint256 tokensPerBNBPresale = allocatedTokensForPresale.div(maxcap); //
uint256 math = (amountToConvertInBNB * 10**decimals).div(10**18); //1 bnb
return (tokensPerBNBPresale * math);
}
Currently if we give this function the variables:
80000000000000000000000000 tokens for presale, with 18 decimals (80000000 tokens)
11000000000000000 ETH maxcap (0.011 eth with 18 decimals)
11000000000000000 ETH amountToConvetInBnb (0.011 eth with 18 decimals)
The function currently returns 79999999992000000000000000 (Which is not correct.)
The function should return 80000000000000000000000000, because we are buying everything up. (0.011 eth of 0.011 eth).
If we put maxcap of 10000000000000000, the function returns fine, however where there might be decimals it messes up somewhere!
Please help me freelancer with fixing this function!
It's urgent!
I need a function that precicely can calculate the users totalpayouts based on 3 variables.
1: The max tokens for sale.
2: The total raised amount needed for the project.
3: Amount the users would want to purchase for.
4: Token decimal of the token we would want to purchase.
I have previously userd this function to calculate users rewards:
function calcTokenRewards(
uint256 allocatedTokensForPresale, //The amount of tokens that is being sold.
uint256 decimals //The amount of decimal the token have.
uint256 maxcap, //The amount that all the tokens combined can be sold for.
uint256 amountToConvertInBNB, //The amount of money we would spend
) private pure returns (uint256) {
uint256 tokensPerBNBPresale = allocatedTokensForPresale.div(maxcap); //
uint256 math = (amountToConvertInBNB * 10**decimals).div(10**18); //1 bnb
return (tokensPerBNBPresale * math);
}
Currently if we give this function the variables:
80000000000000000000000000 tokens for presale, with 18 decimals (80000000 tokens)
11000000000000000 ETH maxcap (0.011 eth with 18 decimals)
11000000000000000 ETH amountToConvetInBnb (0.011 eth with 18 decimals)
The function currently returns 79999999992000000000000000 (Which is not correct.)
The function should return 80000000000000000000000000, because we are buying everything up. (0.011 eth of 0.011 eth).
If we put maxcap of 10000000000000000, the function returns fine, however where there might be decimals it messes up somewhere!
Please help me freelancer with fixing this function!
It's urgent!