Hi @abcoathup
Suppose we have ERC20 token and we initially set rate 1 ETH = 300 TKN and suppose 1 ETH = 150 USD. This means 150 USD = 300 TKN or 1 TKN = 0.5 USD. (Assume Token decimals is 18).
Now let's assume, 2 days later 1 ETH becomes 30 USD, and since we initially set 1 ETH = 300 TKN, 30 USD = 300 TKN, meaning that 1 TKN = 0.1 USD. Lower than before. But my concern is that I want to keep 1TKN constant to some value in USD. For example, 1 TKN = 0.5 USD.
In OZ smart contracts related to crowdsale contract there is no place that takes into account Ether to, say, USD ratio (or any other fiat currency). For example,
/**
* @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_.
* @return The number of tokens a buyer gets per wei at a given time
*/
function getCurrentRate() public view returns (uint256) {
if (!isOpen()) {
return 0;
}
// solhint-disable-next-line not-rely-on-time
uint256 elapsedTime = block.timestamp.sub(openingTime());
uint256 timeRange = closingTime().sub(openingTime());
uint256 rateRange = _initialRate.sub(_finalRate);
return _initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
}
In your example example, you assume assume 1 ETH = $200 and derive the rate value. But this calculations are not done in the smart contract itself, the smart contract is sort of "unaware" of Ether to USD ratio.
So, one possible solution that comes to my mind is to design my smart contract so that we could manually adjust any time (every morning or example) ACCORDING TO the ETH-TO-USD ration.
What is your take on this matter? Any best practices, recommendations, suggestions?