mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
created common getter for current rate
This commit is contained in:
parent
3cc84a904a
commit
07c2b67b63
|
@ -75,11 +75,19 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
emit LogDeploy(token, amount);
|
emit LogDeploy(token, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get pool token rate
|
||||||
|
* @param tokenAmt total token amount
|
||||||
|
*/
|
||||||
|
function getCurrentRate(uint tokenAmt) public {
|
||||||
|
return wdiv(totalSupply(), tokenAmt);
|
||||||
|
}
|
||||||
|
|
||||||
function setExchangeRate() public isChief {
|
function setExchangeRate() public isChief {
|
||||||
uint _previousRate = exchangeRate;
|
uint _previousRate = exchangeRate;
|
||||||
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
||||||
_totalToken = sub(_totalToken, insuranceAmt);
|
_totalToken = sub(_totalToken, insuranceAmt);
|
||||||
uint _currentRate = wdiv(totalSupply(), _totalToken);
|
uint _currentRate = getCurrentRate(_totalToken);
|
||||||
require(_currentRate != 0, "current-rate-is-zero");
|
require(_currentRate != 0, "current-rate-is-zero");
|
||||||
if (_currentRate > _previousRate) {
|
if (_currentRate > _previousRate) {
|
||||||
uint _difTkn = sub(tokenBalance, _totalToken);
|
uint _difTkn = sub(tokenBalance, _totalToken);
|
||||||
|
@ -89,13 +97,13 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
} else {
|
} else {
|
||||||
insuranceAmt = 0;
|
insuranceAmt = 0;
|
||||||
tokenBalance = add(_totalToken, insuranceAmt);
|
tokenBalance = add(_totalToken, insuranceAmt);
|
||||||
_currentRate = wdiv(totalSupply(), tokenBalance);
|
_currentRate = getCurrentRate(tokenBalance);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint insureFeeAmt = wmul(sub(_totalToken, tokenBalance), registry.insureFee(address(this)));
|
uint insureFeeAmt = wmul(sub(_totalToken, tokenBalance), registry.insureFee(address(this)));
|
||||||
insuranceAmt = add(insuranceAmt, insureFeeAmt);
|
insuranceAmt = add(insuranceAmt, insureFeeAmt);
|
||||||
tokenBalance = sub(_totalToken, insureFeeAmt);
|
tokenBalance = sub(_totalToken, insureFeeAmt);
|
||||||
_currentRate = wdiv(totalSupply(), tokenBalance);
|
_currentRate = getCurrentRate(tokenBalance);
|
||||||
}
|
}
|
||||||
exchangeRate = _currentRate;
|
exchangeRate = _currentRate;
|
||||||
emit LogExchangeRate(exchangeRate, tokenBalance, insuranceAmt);
|
emit LogExchangeRate(exchangeRate, tokenBalance, insuranceAmt);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user