Has anyone used rate in Openzeppelin’s crowd sale which is not whole number. As in I am subtracting small amount by every purchase. Just struggling to handle rate when it’s not a whole number.
Update:- as in, is there a possible to way to reduce rate by 0.0028 on every purchase(logic to do it after every purchase is done). I am here mainly struggling with that decimal issue.
Were you able to setup your rate?
@abcoathup Sorry, I missed this somehow. So, I was able to achieve the functionality that I wanted by setting initial rate ‘2000000000000000000’ and decrease it by 0.0014e18 on every purchase to make the increment exactly what In wanted. There is one more step which is required to make it work. I override the method
function _getTokenAmount(uint256 weiAmount) internal view returns (uint256) where I do this
I was having multiple issues, some of them because Solidity doesn’t support decimals yet. I tried using some third party library’s but there was no conversion available for uint256 (the type of rate we have from Openzeppelin). So, this was the solution that worked for me. It was all tested and worked great.
P.S:- If someone is following this, you will need two variables for “rate”, i.e “initialRate” and “currentRate”. Also, you will need to override the “rate” method to return “currentRate”.
I would love to get your thoughts on this @abcoathup.
And thanks for all the support!!!
Glad you were able to get the functionality you wanted. Thanks for sharing.
I recommend anything of value be appropriately tested and audited. You can also document in code comments why and how you are doing what you are doing.
Did both of these things. Btw, I will be writing a tutorial on this in Feb. I hope it will be helpful.