From bb675975cef38b1f14614b796d90773e833f2039 Mon Sep 17 00:00:00 2001 From: Samyak Jain <34437877+KaymasJain@users.noreply.github.com> Date: Sun, 30 Aug 2020 01:24:21 +1000 Subject: [PATCH] withdraw insurance amount function --- contracts/pools/erc20.sol | 13 +++++++++++++ contracts/pools/eth.sol | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/contracts/pools/erc20.sol b/contracts/pools/erc20.sol index 286d68c..90f8305 100644 --- a/contracts/pools/erc20.sol +++ b/contracts/pools/erc20.sol @@ -155,6 +155,19 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable { emit LogAddInsurance(tknAmt); } + function withdrawInsurance(uint tknAmt) external payable { + require(msg.sender == instaIndex.master(), "not-master"); + require(tknAmt <= insuranceAmt || tknAmt == uint(-1), "not-enough-insurance"); + if (tknAmt == uint(-1)) { + baseToken.safeTransfer(msg.sender, insuranceAmt); + insuranceAmt = 0; + } else { + baseToken.safeTransfer(msg.sender, tknAmt); + insuranceAmt = sub(insuranceAmt, tknAmt); + } + emit LogAddInsurance(tknAmt); + } + function shutdown() external { require(msg.sender == instaIndex.master(), "not-master"); paused() ? _unpause() : _pause(); diff --git a/contracts/pools/eth.sol b/contracts/pools/eth.sol index b111308..9fcd145 100644 --- a/contracts/pools/eth.sol +++ b/contracts/pools/eth.sol @@ -148,6 +148,19 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath { emit LogAddInsurance(tknAmt); } + function withdrawInsurance(uint tknAmt) external payable { + require(msg.sender == instaIndex.master(), "not-master"); + require(tknAmt <= insuranceAmt || tknAmt == uint(-1), "not-enough-insurance"); + if (tknAmt == uint(-1)) { + msg.sender.transfer(insuranceAmt); + insuranceAmt = 0; + } else { + msg.sender.transfer(tknAmt); + insuranceAmt = sub(insuranceAmt, tknAmt); + } + emit LogAddInsurance(tknAmt); + } + function shutdown() external { require(msg.sender == instaIndex.master(), "not-master"); paused() ? _unpause() : _pause();