mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
minor code restructuring
This commit is contained in:
parent
0f639489c0
commit
bc531a7aa7
|
@ -66,14 +66,6 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev get pool token rate
|
|
||||||
* @param tokenAmt total token amount
|
|
||||||
*/
|
|
||||||
function getCurrentRate(uint tokenAmt) internal view returns (uint) {
|
|
||||||
return wdiv(totalSupply(), tokenAmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev sets exchange rate
|
* @dev sets exchange rate
|
||||||
*/
|
*/
|
||||||
|
@ -82,7 +74,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
uint _prevRate = exchangeRate;
|
uint _prevRate = exchangeRate;
|
||||||
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
||||||
_totalToken = sub(_totalToken, feeAmt);
|
_totalToken = sub(_totalToken, feeAmt);
|
||||||
uint _newRate = getCurrentRate(_totalToken);
|
uint _newRate = wdiv(totalSupply(), _totalToken);
|
||||||
require(_newRate != 0, "current-rate-is-zero");
|
require(_newRate != 0, "current-rate-is-zero");
|
||||||
uint _tokenBal = wdiv(totalSupply(), _prevRate);
|
uint _tokenBal = wdiv(totalSupply(), _prevRate);
|
||||||
if (_newRate > _prevRate) {
|
if (_newRate > _prevRate) {
|
||||||
|
@ -91,7 +83,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
uint _newFee = wmul(sub(_totalToken, _tokenBal), registry.fee(address(this)));
|
uint _newFee = wmul(sub(_totalToken, _tokenBal), registry.fee(address(this)));
|
||||||
feeAmt = add(feeAmt, _newFee);
|
feeAmt = add(feeAmt, _newFee);
|
||||||
_tokenBal = sub(_totalToken, _newFee);
|
_tokenBal = sub(_totalToken, _newFee);
|
||||||
_newRate = getCurrentRate(_tokenBal);
|
_newRate = wdiv(totalSupply(), _tokenBal);
|
||||||
}
|
}
|
||||||
exchangeRate = _newRate;
|
exchangeRate = _newRate;
|
||||||
emit LogExchangeRate(exchangeRate, _tokenBal, feeAmt);
|
emit LogExchangeRate(exchangeRate, _tokenBal, feeAmt);
|
||||||
|
@ -102,7 +94,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
* @param _target Target to of Connector.
|
* @param _target Target to of Connector.
|
||||||
* @param _data CallData of function in Connector.
|
* @param _data CallData of function in Connector.
|
||||||
*/
|
*/
|
||||||
function spell(address _target, bytes memory _data) internal {
|
function spell(address _target, bytes memory _data) private {
|
||||||
require(_target != address(0), "target-invalid");
|
require(_target != address(0), "target-invalid");
|
||||||
assembly {
|
assembly {
|
||||||
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)
|
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)
|
||||||
|
|
|
@ -65,14 +65,6 @@ contract PoolETH is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev get pool token rate
|
|
||||||
* @param tokenAmt total token amount
|
|
||||||
*/
|
|
||||||
function getCurrentRate(uint tokenAmt) internal view returns (uint) {
|
|
||||||
return wdiv(totalSupply(), tokenAmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev sets exchange rate
|
* @dev sets exchange rate
|
||||||
*/
|
*/
|
||||||
|
@ -81,7 +73,7 @@ contract PoolETH is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
uint _prevRate = exchangeRate;
|
uint _prevRate = exchangeRate;
|
||||||
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
||||||
_totalToken = sub(_totalToken, feeAmt);
|
_totalToken = sub(_totalToken, feeAmt);
|
||||||
uint _newRate = getCurrentRate(_totalToken);
|
uint _newRate = wdiv(totalSupply(), _totalToken);
|
||||||
require(_newRate != 0, "current-rate-is-zero");
|
require(_newRate != 0, "current-rate-is-zero");
|
||||||
uint _tokenBal = wdiv(totalSupply(), _prevRate);
|
uint _tokenBal = wdiv(totalSupply(), _prevRate);
|
||||||
if (_newRate > _prevRate) {
|
if (_newRate > _prevRate) {
|
||||||
|
@ -90,7 +82,7 @@ contract PoolETH is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
uint _newFee = wmul(sub(_totalToken, _tokenBal), registry.fee(address(this)));
|
uint _newFee = wmul(sub(_totalToken, _tokenBal), registry.fee(address(this)));
|
||||||
feeAmt = add(feeAmt, _newFee);
|
feeAmt = add(feeAmt, _newFee);
|
||||||
_tokenBal = sub(_totalToken, _newFee);
|
_tokenBal = sub(_totalToken, _newFee);
|
||||||
_newRate = getCurrentRate(_tokenBal);
|
_newRate = wdiv(totalSupply(), _tokenBal);
|
||||||
}
|
}
|
||||||
exchangeRate = _newRate;
|
exchangeRate = _newRate;
|
||||||
emit LogExchangeRate(exchangeRate, _tokenBal, feeAmt);
|
emit LogExchangeRate(exchangeRate, _tokenBal, feeAmt);
|
||||||
|
@ -101,7 +93,7 @@ contract PoolETH is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
* @param _target Target to of Connector.
|
* @param _target Target to of Connector.
|
||||||
* @param _data CallData of function in Connector.
|
* @param _data CallData of function in Connector.
|
||||||
*/
|
*/
|
||||||
function spell(address _target, bytes memory _data) internal {
|
function spell(address _target, bytes memory _data) private {
|
||||||
require(_target != address(0), "target-invalid");
|
require(_target != address(0), "target-invalid");
|
||||||
assembly {
|
assembly {
|
||||||
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)
|
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user