I'm implementing a fundraising contract where a user can create a fundraiser but when creating they must send a rewardingToken
(ERC20 token) to the contract and the user also specifies a token which is accepted for the fundraiser, called acceptingToken
, and the raise
amount which is the number of acceptingToken
that we are fundraising for.
acceptingToken
can be any ERC20 token.
In this example, Lets assume the total supply of rewardingToken
is 100,000 tokens.
When creating a fundraiser the amount of rewardingToken
deposited is 1000, the raise goal (i.e the number of acceptingToken
we want to raise) is 100.
When the raise goal is met and an investor wants to withdraw the rewardToken
then I calculate it by
uint256 rewardTokens = ((rewardingTokenAmount) /
(raise)) * amtInvestorInvested;
IERC20(rewardingToken).transfer(
msg.sender,
rewardTokens
)
The issue here is if there are decimal number which will end up not giving rewards in an accurate manner, which will cause users to get less than what they deserve.
I initially thought to multiply the rewardingTokenAmount
by 1e18, to have 18 decimal points in accuracy. But then when sending the tokens, I will need to divide by 1e18 which would defeat the purpose of doing that.
Not sure what the best method for this