Added token paramater in deploy function

This commit is contained in:
Thrilok Kumar 2020-08-27 17:26:31 +05:30
parent 27be4fbfd1
commit f63a3fc04d
2 changed files with 24 additions and 11 deletions

View File

@ -2,7 +2,7 @@
pragma solidity ^0.6.8;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
@ -31,7 +31,9 @@ interface RateInterface {
}
contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
event LogDeploy(uint amount);
using SafeERC20 for IERC20;
event LogDeploy(address indexed token, uint amount);
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
event LogSettle(uint settleTime);
event LogDeposit(uint depositAmt, uint poolMintAmt);
@ -62,10 +64,14 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
_;
}
function deploy(address _dsa, uint amount) external isChief {
function deploy(address _dsa, address token, uint amount) external isChief {
require(registry.isDsa(address(this), _dsa), "not-autheticated-dsa");
payable(_dsa).transfer(amount);
emit LogDeploy(amount);
if (token == address(0)) {
payable(_dsa).transfer(amount);
} else {
IERC20(token).safeTransfer(_dsa, amount);
}
emit LogDeploy(token, amount);
}
function setExchangeRate() public isChief {
@ -73,6 +79,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
_totalToken = sub(_totalToken, insuranceAmt);
uint _currentRate = wdiv(totalSupply(), _totalToken);
require(_currentRate != 0, "currentRate-is-0");
if (_currentRate > _previousRate) {
uint difTkn = sub(tokenBalance, _totalToken);
insuranceAmt = sub(insuranceAmt, difTkn);

View File

@ -33,7 +33,7 @@ interface RateInterface {
contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
using SafeERC20 for IERC20;
event LogDeploy(uint amount);
event LogDeploy(address token, uint amount);
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
event LogSettle(uint settleTime);
event LogDeposit(uint depositAmt, uint poolMintAmt);
@ -65,10 +65,16 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
_;
}
function deploy(address _dsa, uint amount) public isChief {
function deploy(address _dsa, address token, uint amount) public isChief {
require(registry.isDsa(address(this), _dsa), "not-autheticated-dsa");
baseToken.safeTransfer(_dsa, amount);
emit LogDeploy(amount);
if (token == address(0)) {
baseToken.safeTransfer(_dsa, amount);
} else if (token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE){
payable(_dsa).transfer(amount);
} else {
IERC20(token).safeTransfer(_dsa, amount);
}
emit LogDeploy(token, amount);
}
function setExchangeRate() public isChief {
@ -76,13 +82,13 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
_totalToken = sub(_totalToken, insuranceAmt);
uint _currentRate = wdiv(totalSupply(), _totalToken);
require(_currentRate != 0, "currentRate-is-0");
if (_currentRate > _previousRate) {
uint difTkn = sub(tokenBalance, _totalToken);
insuranceAmt = sub(insuranceAmt, difTkn);
_currentRate = _previousRate;
} else {
uint fee = registry.insureFee(address(this));
uint insureFeeAmt = wmul(sub(_totalToken, tokenBalance), fee);
uint insureFeeAmt = wmul(sub(_totalToken, tokenBalance), registry.insureFee(address(this)));
insuranceAmt = add(insuranceAmt, insureFeeAmt);
tokenBalance = sub(_totalToken, insureFeeAmt);
_currentRate = wdiv(totalSupply(), tokenBalance);