added withdrawal fee

This commit is contained in:
Samyak Jain 2020-08-30 22:50:37 +10:00
parent b73c7be2e1
commit e79e2cd970
3 changed files with 33 additions and 5 deletions

View File

@ -24,6 +24,7 @@ interface RegistryInterface {
function poolLogic(address) external returns (address);
function poolCap(address) external view returns (uint);
function insureFee(address) external view returns (uint);
function withdrawalFee(address) external view returns (uint);
function isDsa(address, address) external view returns (bool);
}
@ -38,7 +39,7 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
event LogSettle(uint settleTime);
event LogDeposit(uint depositAmt, uint poolMintAmt);
event LogWithdraw(uint withdrawAmt, uint poolBurnAmt);
event LogWithdraw(uint withdrawAmt, uint poolBurnAmt, uint feeAmt);
event LogAddInsurance(uint amount);
event LogPausePool(bool);
@ -144,14 +145,22 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
_burn(msg.sender, _burnAmt);
uint _withdrawalFee = registry.withdrawalFee(address(this));
uint _feeAmt;
if (_withdrawalFee > 0) {
_feeAmt = wmul(_tknAmt, _withdrawalFee);
insuranceAmt = add(insuranceAmt, _feeAmt);
_tknAmt = sub(_tknAmt, _feeAmt);
}
baseToken.safeTransfer(to, _tknAmt);
emit LogWithdraw(tknAmt, _burnAmt);
emit LogWithdraw(tknAmt, _burnAmt, _feeAmt);
}
function addInsurance(uint tknAmt) external payable {
baseToken.safeTransferFrom(msg.sender, address(this), tknAmt);
insuranceAmt += tknAmt;
insuranceAmt = add(insuranceAmt, tknAmt);
emit LogAddInsurance(tknAmt);
}

View File

@ -23,6 +23,7 @@ interface RegistryInterface {
function poolLogic(address) external returns (address);
function poolCap(address) external view returns (uint);
function insureFee(address) external view returns (uint);
function withdrawalFee(address) external view returns (uint);
function isDsa(address, address) external view returns (bool);
}
@ -37,7 +38,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
event LogSettle(uint settleTime);
event LogDeposit(uint depositAmt, uint poolMintAmt);
event LogWithdraw(uint withdrawAmt, uint poolBurnAmt);
event LogWithdraw(uint withdrawAmt, uint poolBurnAmt, uint feeAmt);
event LogAddInsurance(uint amount);
event LogPausePool(bool);
@ -137,9 +138,17 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
_burn(msg.sender, _burnAmt);
uint _withdrawalFee = registry.withdrawalFee(address(this));
uint _feeAmt;
if (_withdrawalFee > 0) {
_feeAmt = wmul(_tknAmt, _withdrawalFee);
insuranceAmt = add(insuranceAmt, _feeAmt);
_tknAmt = sub(_tknAmt, _feeAmt);
}
payable(to).transfer(_tknAmt);
emit LogWithdraw(tknAmt, _burnAmt);
emit LogWithdraw(tknAmt, _burnAmt, _feeAmt);
}
function addInsurance(uint tknAmt) external payable {

View File

@ -18,6 +18,7 @@ contract Registry {
event LogUpdatePoolCap(address pool, uint newCap);
event LogUpdatePoolLogic(address pool, address newLogic);
event LogUpdateInsureFee(address pool, uint newFee);
event LogUpdateWithdrawalFee(address pool, uint newFee);
event LogAddPool(address indexed token, address indexed pool);
event LogRemovePool(address indexed token, address indexed pool);
event LogNewDSA(address indexed pool, address indexed dsa);
@ -32,6 +33,7 @@ contract Registry {
mapping (address => address) public poolLogic;
mapping (address => uint) public poolCap;
mapping (address => uint) public insureFee;
mapping (address => uint) public withdrawalFee;
mapping (address => mapping(address => bool)) public isDsa; // Pool => DSA address => true/false
mapping (address => address[]) public dsaArr; // Pool => all dsa in array
@ -145,6 +147,14 @@ contract Registry {
emit LogUpdateInsureFee(_pool, _newFee);
}
function updateWithdrawalFee(address _pool, uint _newFee) external isMaster {
require(isPool[_pool], "not-pool");
require(_newFee < 5 ** 16, "insure-fee-limit-reached");
require(withdrawalFee[_pool] != _newFee, "same-pool-fee");
withdrawalFee[_pool] = _newFee;
emit LogUpdateWithdrawalFee(_pool, _newFee);
}
function addDsa(address _pool, address _dsa) external isMaster {
require(isPool[_pool], "not-pool");
if (_dsa == address(0)) {