diff --git a/contracts/CapitalAgent.sol b/contracts/CapitalAgent.sol index 4880827b..46f0633e 100644 --- a/contracts/CapitalAgent.sol +++ b/contracts/CapitalAgent.sol @@ -4,6 +4,7 @@ pragma solidity =0.8.23; import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; +import "@openzeppelin/contracts/utils/Strings.sol"; import "./interfaces/ISalesPolicy.sol"; import "./interfaces/IExchangeAgent.sol"; import "./interfaces/ICapitalAgent.sol"; @@ -15,7 +16,7 @@ import "./interfaces/ICapitalAgent.sol"; **/ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessControlUpgradeable { bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); - + using Strings for uint256; address public exchangeAgent; address public salesPolicyFactory; address public usdcToken; @@ -25,7 +26,6 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro uint256 totalCapital; address currency; bool exist; - uint256 totalWithdrawPendingCapital; } struct PolicyInfo { @@ -43,11 +43,20 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro PolicyInfo public policyInfo; - uint256 public totalUtilizedAmount; - // Maximum Leverage Ratio uint256 public MLR; + /* + Value in %. 80 means 80% of the total MLR value + Currently we use the MLR to allow users to buy coverages. + The idea with the new approach is to add a safety margin on top of + the MLR so that we can only sell coverages for about 80% of the MLR. + That means that if the MLR is 200% and the pool has 100k tokens, we could + only sell 160k in coverage. At the same time, if 160k are sold in coverages, + we need to make sure that the pools always have at least 80k tokens. + */ + uint256 public MLR_THRESHOLD = 80; + uint256 public constant CALC_PRECISION = 1e18; mapping(address => bool) public poolWhiteList; @@ -63,8 +72,7 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro event LogUpdatePolicyCoverage( address indexed _policy, uint256 _amount, - uint256 _policyUtilized, - uint256 _totalUtilizedAmount + uint256 _policyUtilized ); event LogUpdatePolicyExpired(address indexed _policy, uint256 _policyTokenId); event LogMarkToClaimPolicy(address indexed _policy, uint256 _policyTokenId); @@ -75,7 +83,6 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro event LogRemovePoolWhiteList(address indexed _pool); event LogSetOperator(address indexed _operator); event LogSetUSDC(address indexed _usdcToken); - event LogupdatePoolWithdrawPendingCapital(address indexed _ssip, uint256 _poolPendingCapital); function initialize( address _exchangeAgent, @@ -110,9 +117,9 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro return (_policy.policy, _policy.utilizedAmount, _policy.exist); } - function getPoolInfo(address _pool) external view returns (uint256, address, bool, uint256) { + function getPoolInfo(address _pool) external view returns (uint256, address, bool) { PoolInfo memory _poolInfo = poolInfo[_pool]; - return (_poolInfo.totalCapital, _poolInfo.currency, _poolInfo.exist, _poolInfo.totalWithdrawPendingCapital); + return (_poolInfo.totalCapital, _poolInfo.currency, _poolInfo.exist); } // Getter function to return the poolList array @@ -180,7 +187,7 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro * @dev return total capital in usdc staked in capital agent by pools **/ function totalCapitalStaked() public view returns (uint256) { - return _getTotalCapitalStakedInUSDC(); + return _getTotalCapitalAvailableInUSDC(); } /** @@ -220,7 +227,7 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro } poolList.push(_ssip); - poolInfo[_ssip] = PoolInfo({totalCapital: 0, currency: _currency, exist: true, totalWithdrawPendingCapital: 0}); + poolInfo[_ssip] = PoolInfo({totalCapital: 0, currency: _currency, exist: true}); emit LogAddPool(_ssip, _currency); } @@ -238,7 +245,7 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro existedCurrencies[_currency] = true; currencyList.push(_currency); } - poolInfo[_ssip] = PoolInfo({totalCapital: 0, currency: _currency, exist: true, totalWithdrawPendingCapital: 0}); + poolInfo[_ssip] = PoolInfo({totalCapital: 0, currency: _currency, exist: true}); poolList.push(_ssip); emit LogAddPool(_ssip, _currency); } @@ -292,7 +299,6 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro **/ function removePolicy() external onlyRole(ADMIN_ROLE) nonReentrant { require(policyInfo.exist, "UnoRe: non existing policy on Capital Agent"); - totalUtilizedAmount = 0; address _policy = policyInfo.policy; policyInfo.policy = address(0); policyInfo.exist = false; @@ -308,9 +314,8 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro **/ function SSIPWithdraw(uint256 _withdrawAmount) external override nonReentrant { require(poolInfo[msg.sender].exist, "UnoRe: no exist ssip"); - require(_checkCapitalByMLR(msg.sender, _withdrawAmount), "UnoRe: minimum capital underflow"); + _checkCapitalByMLR(msg.sender, _withdrawAmount); _updatePoolCapital(msg.sender, _withdrawAmount, false); - _updatePoolWithdrawPendingCapital(msg.sender, _withdrawAmount, false); } /** @@ -351,11 +356,6 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro _updatePoolCapital(msg.sender, _stakingAmount, true); } - function updatePoolWithdrawPendingCapital(address _pool, uint256 _amount, bool isAdd) external nonReentrant { - require(poolInfo[msg.sender].exist, "UnoRe: no exist ssip"); - _updatePoolWithdrawPendingCapital(_pool, _amount, isAdd); - } - /** * @dev return if pool can withdraw this amount, * remaning pool capital times MLR should be greater than or equal to the totalPremiumSold @@ -430,41 +430,27 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro emit LogUpdatePoolCapital(_pool, poolInfo[_pool].totalCapital, totalCapitalStakedByCurrency[currency]); } - function _updatePoolWithdrawPendingCapital(address _pool, uint256 _amount, bool isAdd) private { - if (!isAdd) { - require(poolInfo[_pool].totalWithdrawPendingCapital >= _amount, "UnoRe: total Capital Pending underflow"); - } - poolInfo[_pool].totalWithdrawPendingCapital = isAdd - ? poolInfo[_pool].totalWithdrawPendingCapital + _amount - : poolInfo[_pool].totalWithdrawPendingCapital - _amount; - emit LogupdatePoolWithdrawPendingCapital(_pool, poolInfo[_pool].totalWithdrawPendingCapital); - } - function _updatePolicyCoverage(uint256 _amount, bool isAdd) private { if (!isAdd) { require(policyInfo.utilizedAmount >= _amount, "UnoRe: policy coverage overflow"); } policyInfo.utilizedAmount = isAdd ? policyInfo.utilizedAmount + _amount : policyInfo.utilizedAmount - _amount; - totalUtilizedAmount = isAdd ? totalUtilizedAmount + _amount : totalUtilizedAmount - _amount; - emit LogUpdatePolicyCoverage(policyInfo.policy, _amount, policyInfo.utilizedAmount, totalUtilizedAmount); + emit LogUpdatePolicyCoverage(policyInfo.policy, _amount, policyInfo.utilizedAmount); } function _checkCapitalByMLR(address _pool, uint256 _withdrawAmount) private view returns (bool) { address currency = poolInfo[_pool].currency; - uint256 totalCapitalStakedInUSDC; - uint256 totalWithdrawPendingCapital; - + uint256 totalCapitalAvailableInUSDC; //Withdraw amount in USDC uint256 withdrawInUSDC = _convertTokenToUSDC(currency, _withdrawAmount); //Total Capital Staked in Pools - totalCapitalStakedInUSDC = _convertTokenToUSDC(currency, _getTotalCapitalStakedInUSDC()); - //Total Capital pending in withdraw - totalWithdrawPendingCapital = _getTotalPendingCapitalInUSDC(); - uint256 totalInPoolInUSDC = totalCapitalStakedInUSDC - totalWithdrawPendingCapital; + totalCapitalAvailableInUSDC = _convertTokenToUSDC(currency, _getTotalCapitalAvailableInUSDC()); + + uint256 maxWithdrawAmountInUSDC = (((totalCapitalAvailableInUSDC) * MLR) / CALC_PRECISION) - policyInfo.utilizedAmount; - bool isMLRPass = totalUtilizedAmount <= ((totalInPoolInUSDC - withdrawInUSDC) * MLR) / CALC_PRECISION; + require(maxWithdrawAmountInUSDC >= withdrawInUSDC, string.concat("UnoRe: max ammount is", maxWithdrawAmountInUSDC.toString())); - return isMLRPass; + return policyInfo.utilizedAmount <= ((totalCapitalAvailableInUSDC - withdrawInUSDC) * MLR) / CALC_PRECISION; } function _convertTokenToUSDC(address _currency, uint256 _amount) private view returns (uint256) { @@ -480,7 +466,7 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro return tokenInUSDC; } - function _getTotalCapitalStakedInUSDC() private view returns (uint256) { + function _getTotalCapitalAvailableInUSDC() private view returns (uint256) { uint256 totalCapitalStakedInUSDC; for (uint256 i = 0; i < currencyList.length; i++) { address currency = currencyList[i]; @@ -491,32 +477,12 @@ contract CapitalAgent is ICapitalAgent, ReentrancyGuardUpgradeable, AccessContro return totalCapitalStakedInUSDC; } - function getTotalPendingCapitalInUSDC() public view returns (uint256) { - return _getTotalPendingCapitalInUSDC(); - } - - /** - * @dev returns total value in "pending" state from all pools - **/ - function _getTotalPendingCapitalInUSDC() private view returns (uint256) { - uint256 totalPendingCapitalInUSDC; - for (uint256 i = 0; i < poolList.length; i++) { - if (poolInfo[poolList[i]].exist == true) { - totalPendingCapitalInUSDC = - totalPendingCapitalInUSDC + - _convertTokenToUSDC(poolInfo[poolList[i]].currency, poolInfo[poolList[i]].totalWithdrawPendingCapital); - } - } - return totalPendingCapitalInUSDC; - } - function _checkCoverageByMLR(uint256 _newCoverageAmount) private view returns (bool) { - uint256 totalCapitalStakedInUSDC = _getTotalCapitalStakedInUSDC(); - uint256 totalCapitalPendingInUSDC = _getTotalPendingCapitalInUSDC(); - uint256 scaledMLR = MLR / CALC_PRECISION; + uint256 totalCapitalStakedInUSDC = _getTotalCapitalAvailableInUSDC(); + uint256 availableCoverage = totalCapitalStakedInUSDC * MLR / CALC_PRECISION; + return - totalUtilizedAmount + _newCoverageAmount <= - ((totalCapitalStakedInUSDC - totalCapitalPendingInUSDC) * scaledMLR); + policyInfo.utilizedAmount + _newCoverageAmount <= (availableCoverage * MLR_THRESHOLD / 100); } /** diff --git a/contracts/PremiumPool.sol b/contracts/PremiumPool.sol index 076e8156..1a9577fd 100644 --- a/contracts/PremiumPool.sol +++ b/contracts/PremiumPool.sol @@ -35,8 +35,6 @@ contract PremiumPool is IPremiumPool, ReentrancyGuard, AccessControl, Pausable { event PremiumWithdraw(address indexed _currency, address indexed _to, uint256 _amount); event LogBuyBackAndBurn(address indexed _operator, address indexed _premiumPool, uint256 _unoAmount); event LogCollectPremium(address indexed _from, address _premiumCurrency, uint256 _premiumAmount); - event LogDepositToSyntheticSSRPRewarder(address indexed _rewarder, uint256 _amountDeposited); - event LogDepositToSyntheticSSIPRewarder(address indexed _rewarder, address indexed _currency, uint256 _amountDeposited); event LogAddCurrency(address indexed _premiumPool, address indexed _currency); event LogRemoveCurrency(address indexed _premiumPool, address indexed _currency); event LogMaxApproveCurrency(address indexed _premiumPool, address indexed _currency, address indexed _to); @@ -133,59 +131,6 @@ contract PremiumPool is IPremiumPool, ReentrancyGuard, AccessControl, Pausable { emit LogCollectPremium(msg.sender, _premiumCurrency, _premiumAmount); } - function depositToSyntheticSSRPRewarder(address _rewarder) external onlyRole(ADMIN_ROLE) whenNotPaused nonReentrant { - require(_rewarder != address(0), "UnoRe: zero address"); - enforceHasContractCode(_rewarder, "UnoRe: no contract address"); - uint256 usdcAmountToDeposit = 0; - if (ssrpPremiumEth > 0) { - TransferHelper.safeTransferETH(exchangeAgent, ssrpPremiumEth); - uint256 convertedAmount = IExchangeAgent(exchangeAgent).convertForToken(address(0), usdcToken, ssrpPremiumEth); - usdcAmountToDeposit += convertedAmount; - ssrpPremiumEth = 0; - } - for (uint256 ii = 0; ii < availableCurrencyList.length; ii++) { - if (ssrpPremium[availableCurrencyList[ii]] > 0) { - if (availableCurrencyList[ii] == usdcToken) { - usdcAmountToDeposit += ssrpPremium[availableCurrencyList[ii]]; - } else { - uint256 convertedUSDCAmount = IExchangeAgent(exchangeAgent).convertForToken( - availableCurrencyList[ii], - usdcToken, - ssrpPremium[availableCurrencyList[ii]] - ); - usdcAmountToDeposit += convertedUSDCAmount; - } - ssrpPremium[availableCurrencyList[ii]] = 0; - } - } - if (usdcAmountToDeposit > 0) { - TransferHelper.safeTransfer(usdcToken, _rewarder, usdcAmountToDeposit); - emit LogDepositToSyntheticSSRPRewarder(_rewarder, usdcAmountToDeposit); - } - } - - function depositToSyntheticSSIPRewarder( - address _currency, - address _rewarder, - uint256 _amount - ) external onlyRole(ADMIN_ROLE) whenNotPaused nonReentrant { - require(_rewarder != address(0), "UnoRe: zero address"); - enforceHasContractCode(_rewarder, "UnoRe: no contract address"); - if (_currency == address(0) && ssipPremiumEth > 0) { - require(_amount <= ssipPremiumEth, "UnoRe: premium balance overflow"); - TransferHelper.safeTransferETH(_rewarder, _amount); - ssipPremiumEth -= _amount; - emit LogDepositToSyntheticSSIPRewarder(_rewarder, _currency, _amount); - } else { - if (availableCurrencies[_currency] && ssipPremium[_currency] > 0) { - require(_amount <= ssipPremium[_currency], "UnoRe: premium balance overflow"); - TransferHelper.safeTransfer(_currency, _rewarder, _amount); - ssipPremium[_currency] -= _amount; - emit LogDepositToSyntheticSSIPRewarder(_rewarder, _currency, _amount); - } - } - } - function buyBackAndBurn() external onlyRole(ADMIN_ROLE) isAlive whenNotPaused { uint256 unoAmount = 0; if (backBurnPremiumEth > 0) { diff --git a/contracts/RiskPool.sol b/contracts/RiskPool.sol index 5d570056..dc7d3d5a 100644 --- a/contracts/RiskPool.sol +++ b/contracts/RiskPool.sol @@ -15,13 +15,13 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { address public SSRP; address public override currency; // for now we should accept only UNO - uint256 public override lpPriceUno; + uint256 public override lpPrice; // UNO value per lp uint256 public MIN_LP_CAPITAL = 1e7; event LogCancelWithdrawRequest(address indexed _user, uint256 _amount, uint256 _amountInUno); event LogPolicyClaim(address indexed _user, uint256 _amount); event LogMigrateLP(address indexed _user, address indexed _migrateTo, uint256 _unoAmount); - event LogLeaveFromPending(address indexed _user, uint256 _withdrawLpAmount, uint256 _withdrawUnoAmount); + event LogLeaveFromPending(address indexed _user, uint256 _withdrawUnoAmount); constructor(string memory _name, string memory _symbol, address _SSRP, address _currency) { require(_SSRP != address(0), "UnoRe: zero pool address"); @@ -29,7 +29,7 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { symbol = _symbol; SSRP = _SSRP; currency = _currency; - lpPriceUno = 1e18; + lpPrice = 1e18; if (_currency == address(0)) { MIN_LP_CAPITAL = 7 * 1e15; } @@ -50,63 +50,39 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { * @dev Users can stake only through Cohort */ function enter(address _from, uint256 _amount) external override onlySSRP { - _mint(_from, (_amount * 1e18) / lpPriceUno); + _mint(_from, (_amount * 1e18) / lpPrice); } /** - * @param _amount UNO amount to withdraw + * @dev withdraw tokens from pool. only pool contract can call this function + * @returns lp Amount and token amount */ - function leaveFromPoolInPending(address _to, uint256 _amount) external override onlySSRP { - require(totalSupply() > 0, "UnoRe: There's no remaining in the pool"); - uint256 requestAmountInLP = (_amount * 1e18) / lpPriceUno; - require( - (requestAmountInLP + uint256(withdrawRequestPerUser[_to].pendingAmount)) <= balanceOf(_to), - "UnoRe: lp balance overflow" - ); - _withdrawRequest(_to, requestAmountInLP, _amount); - } - - /** - * @dev withdraw from pending, only pool contract can call this function - */ - function leaveFromPending(address _to, uint256 _amount) external override onlySSRP returns (uint256, uint256) { - uint256 cryptoBalance = currency != address(0) ? IERC20(currency).balanceOf(address(this)) : address(this).balance; - uint256 pendingAmount = uint256(withdrawRequestPerUser[_to].pendingAmount); - require(_amount <= pendingAmount, "Amount should less than pending amount"); - require(cryptoBalance > 0, "UnoRe: zero uno balance"); + function withdraw(address _to, uint256 _amount) external override onlySSRP returns (uint256,uint256) { + uint256 contractBalance = currency != address(0) ? IERC20(currency).balanceOf(address(this)) : address(this).balance; + require(contractBalance > 0, "UnoRe: zero uno balance"); require(balanceOf(_to) >= _amount, "UnoRe: lp balance overflow"); - uint256 amountInUno = (_amount * lpPriceUno) / 1e18; - if (cryptoBalance - MIN_LP_CAPITAL > amountInUno) { - _withdrawImplement(_to); + uint256 amountInUno = (_amount * lpPrice) / 1e18; + if (contractBalance - MIN_LP_CAPITAL > amountInUno) { + _burn(_to, _amount); if (currency != address(0)) { TransferHelper.safeTransfer(currency, _to, amountInUno); } else { TransferHelper.safeTransferETH(_to, amountInUno); } - emit LogLeaveFromPending(_to, pendingAmount, amountInUno); - return (pendingAmount, amountInUno); + emit LogLeaveFromPending(_to, amountInUno); + return (_amount,amountInUno); } else { - _withdrawImplementIrregular(_to, ((cryptoBalance - MIN_LP_CAPITAL) * 1e18) / lpPriceUno); + _burn(_to, ((contractBalance - MIN_LP_CAPITAL) * 1e18) / lpPrice); if (currency != address(0)) { - TransferHelper.safeTransfer(currency, _to, cryptoBalance - MIN_LP_CAPITAL); + TransferHelper.safeTransfer(currency, _to, contractBalance - MIN_LP_CAPITAL); } else { - TransferHelper.safeTransferETH(_to, cryptoBalance - MIN_LP_CAPITAL); + TransferHelper.safeTransferETH(_to, contractBalance - MIN_LP_CAPITAL); } - emit LogLeaveFromPending(_to, ((cryptoBalance - MIN_LP_CAPITAL) * 1e18) / lpPriceUno, cryptoBalance - MIN_LP_CAPITAL); - return (((cryptoBalance - MIN_LP_CAPITAL) * 1e18) / lpPriceUno, cryptoBalance - MIN_LP_CAPITAL); + emit LogLeaveFromPending(_to, contractBalance - MIN_LP_CAPITAL); + return (((contractBalance - MIN_LP_CAPITAL) * 1e18) / lpPrice, contractBalance - MIN_LP_CAPITAL); } } - /** - * @dev cancel pending request, only pool contract can call this function - */ - function cancelWithdrawRequest(address _to) external override onlySSRP returns (uint256, uint256) { - uint256 _pendingAmount = uint256(withdrawRequestPerUser[_to].pendingAmount); - require(_pendingAmount > 0, "UnoRe: zero amount"); - _cancelWithdrawRequest(_to); - emit LogCancelWithdrawRequest(_to, _pendingAmount, (_pendingAmount * lpPriceUno) / 1e18); - return (_pendingAmount, (_pendingAmount * lpPriceUno) / 1e18); - } /** * @dev claim policy to `_to` by `_amount`, only pool contract can call this function @@ -133,7 +109,7 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { emit LogPolicyClaim(_to, cryptoBalance - MIN_LP_CAPITAL); } cryptoBalance = currency != address(0) ? IERC20(currency).balanceOf(address(this)) : address(this).balance; - lpPriceUno = (cryptoBalance * 1e18) / totalSupply(); // UNO value per lp + lpPrice = (cryptoBalance * 1e18) / totalSupply(); // UNO value per lp } /** @@ -142,8 +118,8 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { function emergencyWithdraw(address _to, uint256 _amount) external override onlySSRP returns (bool) { uint256 cryptoBalance = currency != address(0) ? IERC20(currency).balanceOf(address(this)) : address(this).balance; require(cryptoBalance > 0, "UnoRe: zero uno balance"); - _emergencyWithdraw(_to); - uint256 amount = (_amount * lpPriceUno) / 1e18; + _burn(_to, _amount); + uint256 amount = (_amount * lpPrice) / 1e18; if (currency != address(0)) { TransferHelper.safeTransfer(currency, _to, amount); } else { @@ -156,31 +132,17 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { require(_migrateTo != address(0), "UnoRe: zero address"); uint256 migratedAmount; uint256 cryptoBalance; - if (_isUnLocked && withdrawRequestPerUser[_to].pendingAmount > 0) { - uint256 pendingAmountInUno = (uint256(withdrawRequestPerUser[_to].pendingAmount) * lpPriceUno) / 1e18; + if (_isUnLocked) { cryptoBalance = currency != address(0) ? IERC20(currency).balanceOf(address(this)) : address(this).balance; - if (pendingAmountInUno < cryptoBalance - MIN_LP_CAPITAL) { - if (currency != address(0)) { - TransferHelper.safeTransfer(currency, _to, pendingAmountInUno); - } else { - TransferHelper.safeTransferETH(_to, pendingAmountInUno); - } - _withdrawImplement(_to); + if (currency != address(0)) { + TransferHelper.safeTransfer(currency, _to, cryptoBalance - MIN_LP_CAPITAL); } else { - if (currency != address(0)) { - TransferHelper.safeTransfer(currency, _to, cryptoBalance - MIN_LP_CAPITAL); - } else { - TransferHelper.safeTransferETH(_to, cryptoBalance - MIN_LP_CAPITAL); - } - _withdrawImplementIrregular(_to, ((cryptoBalance - MIN_LP_CAPITAL) * 1e18) / lpPriceUno); - } - } else { - if (withdrawRequestPerUser[_to].pendingAmount > 0) { - _cancelWithdrawRequest(_to); + TransferHelper.safeTransferETH(_to, cryptoBalance - MIN_LP_CAPITAL); } + _burn(_to, ((cryptoBalance - MIN_LP_CAPITAL) * 1e18) / lpPrice); } cryptoBalance = currency != address(0) ? IERC20(currency).balanceOf(address(this)) : address(this).balance; - uint256 unoBalance = (balanceOf(_to) * lpPriceUno) / 1e18; + uint256 unoBalance = (balanceOf(_to) * lpPrice) / 1e18; if (unoBalance < cryptoBalance - MIN_LP_CAPITAL) { if (currency != address(0)) { TransferHelper.safeTransfer(currency, _migrateTo, unoBalance); @@ -210,25 +172,10 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { MIN_LP_CAPITAL = _minLPCapital; } - /** - * @dev return user withdraw request amount, amount in uno and time - */ - function getWithdrawRequest(address _to) external view override onlySSRP returns (uint256, uint256, uint256) { - return ( - uint256(withdrawRequestPerUser[_to].pendingAmount), - uint256(withdrawRequestPerUser[_to].requestTime), - withdrawRequestPerUser[_to].pendingUno - ); - } - - function getTotalWithdrawRequestAmount() external view override onlySSRP returns (uint256) { - return totalWithdrawPending; - } - function transfer(address recipient, uint256 amount) external override returns (bool) { require( - balanceOf(msg.sender) - uint256(withdrawRequestPerUser[msg.sender].pendingAmount) >= amount, - "ERC20: transfer amount exceeds balance or pending WR" + balanceOf(msg.sender) >= amount, + "ERC20: transfer amount exceeds balance" ); _transfer(msg.sender, recipient, amount); @@ -238,8 +185,8 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) { require( - balanceOf(sender) - uint256(withdrawRequestPerUser[sender].pendingAmount) >= amount, - "ERC20: transfer amount exceeds balance or pending WR" + balanceOf(sender)>= amount, + "ERC20: transfer amount exceeds balance" ); _transfer(sender, recipient, amount); @@ -250,7 +197,7 @@ contract RiskPool is IRiskPool, RiskPoolERC20 { return true; } - function setLpPriceUno(uint256 _lpPriceUno) external onlySSRP { - lpPriceUno = _lpPriceUno; + function setlpPrice(uint256 _lpPrice) external onlySSRP { + lpPrice = _lpPrice; } } diff --git a/contracts/RiskPoolERC20.sol b/contracts/RiskPoolERC20.sol index 8690dd7e..b18d7d05 100644 --- a/contracts/RiskPoolERC20.sol +++ b/contracts/RiskPoolERC20.sol @@ -34,14 +34,6 @@ contract RiskPoolERC20 is Context, IRiskPoolERC20 { mapping(address => mapping(address => uint256)) internal _allowances; - struct UserWithdrawRequestInfo { - uint256 pendingAmount; - uint256 requestTime; - uint256 pendingUno; - } - mapping(address => UserWithdrawRequestInfo) internal withdrawRequestPerUser; - uint256 internal totalWithdrawPending; - uint256 private _totalSupply; uint256[30] __gap; @@ -299,53 +291,4 @@ contract RiskPoolERC20 is Context, IRiskPoolERC20 { * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} - - function _withdrawRequest(address _user, uint256 _amount, uint256 _amountInUno) internal { - require(balanceOf(_user) >= _amount, "UnoRe: balance overflow"); - require(_amount <= type(uint128).max, "Amount exceeds max uint128"); - if (withdrawRequestPerUser[_user].pendingAmount == 0 && withdrawRequestPerUser[_user].requestTime == 0) { - withdrawRequestPerUser[_user] = UserWithdrawRequestInfo({ - pendingAmount: _amount, - requestTime: block.timestamp, - pendingUno: _amountInUno - }); - } else { - withdrawRequestPerUser[_user].pendingAmount += _amount; - withdrawRequestPerUser[_user].pendingUno += _amountInUno; - withdrawRequestPerUser[_user].requestTime = block.timestamp; - } - totalWithdrawPending += _amount; - } - - function _withdrawImplement(address _user) internal { - require(uint256(withdrawRequestPerUser[_user].pendingAmount) > 0, "UnoRe: zero claim amount"); - uint256 _pendingAmount = withdrawRequestPerUser[_user].pendingAmount; - totalWithdrawPending -= _pendingAmount; - _burn(_user, _pendingAmount); - delete withdrawRequestPerUser[_user]; - } - - function _withdrawImplementIrregular(address _user, uint256 _amount) internal { - require(uint256(withdrawRequestPerUser[_user].pendingAmount) > 0, "UnoRe: zero claim amount"); - require(uint256(withdrawRequestPerUser[_user].pendingAmount) >= _amount, "UnoRe: pending amount overflow"); - uint256 _pendingAmount = withdrawRequestPerUser[_user].pendingAmount; - totalWithdrawPending -= _pendingAmount; - _burn(_user, _amount); - delete withdrawRequestPerUser[_user]; - } - - function _emergencyWithdraw(address _user) internal { - uint256 _pendingAmount = withdrawRequestPerUser[_user].pendingAmount; - totalWithdrawPending -= _pendingAmount; - if (_pendingAmount > 0) { - _burn(_user, _pendingAmount); - } - delete withdrawRequestPerUser[_user]; - } - - function _cancelWithdrawRequest(address _user) internal { - uint256 _pendingAmount = withdrawRequestPerUser[_user].pendingAmount; - totalWithdrawPending -= _pendingAmount; - delete withdrawRequestPerUser[_user]; - } } diff --git a/contracts/SingleSidedInsurancePool.sol b/contracts/SingleSidedInsurancePool.sol index 8c25d7ab..1d26ce9c 100644 --- a/contracts/SingleSidedInsurancePool.sol +++ b/contracts/SingleSidedInsurancePool.sol @@ -30,7 +30,6 @@ contract SingleSidedInsurancePool is address public migrateTo; address public capitalAgent; - bool public killed; bool public emergencyWithdrawAllowed; address public rewarder; @@ -71,7 +70,7 @@ contract SingleSidedInsurancePool is event LeftPool(address indexed _staker, address indexed _pool, uint256 _requestAmount); event LogUpdatePool(uint256 _lastRewardBlock, uint256 _lpSupply, uint256 _accUnoPerShare); event Harvest(address indexed _user, address indexed _receiver, uint256 _amount); - event LogLeaveFromPendingSSIP( + event LogWithdrawSSIP( address indexed _user, address indexed _riskPool, uint256 _withdrawLpAmount, @@ -89,9 +88,6 @@ contract SingleSidedInsurancePool is event LogSetMinLPCapital(address indexed _SSIP, uint256 _minLPCapital); event LogSetLockTime(address indexed _SSIP, uint256 _lockTime); event LogSetStakingStartTime(address indexed _SSIP, uint256 _startTime); - event PoolAlived(address indexed _owner, bool _alive); - event PoolFailed(address indexed _owner, bool _fail); - event KillPool(address indexed _owner, bool _killed); event InsurancePayoutSettled(uint256 indexed policyId, address indexed payout, uint256 amount); event RollOverReward(address[] indexed _staker, address indexed _pool, uint256 _amount); event EmergencyWithdraw(address indexed user, uint256 amount); @@ -121,11 +117,6 @@ contract SingleSidedInsurancePool is _; } - modifier isAlive() { - require(!killed, "UnoRe: pool is killed"); - _; - } - /** * @dev pause pool to restrict pool functionality, can only by called by admin role */ @@ -140,26 +131,10 @@ contract SingleSidedInsurancePool is _unpause(); } - /** - * @dev kill pool to restrict pool functionality, can only by called by admin role - */ - function killPool() external onlyRole(ADMIN_ROLE) roleLockTimePassed(ADMIN_ROLE) { - killed = true; - emit KillPool(msg.sender, true); - } - - /** - * @dev revive pool, can only by called by admin role - */ - function revivePool() external onlyRole(ADMIN_ROLE) roleLockTimePassed(ADMIN_ROLE) { - killed = false; - emit PoolAlived(msg.sender, false); - } - function setRole( bytes32 _role, address _account - ) external onlyRole(ADMIN_ROLE) roleLockTimePassed(ADMIN_ROLE) whenNotPaused isAlive { + ) external onlyRole(ADMIN_ROLE) roleLockTimePassed(ADMIN_ROLE) whenNotPaused { require(_account != address(0), "UnoRe: zero address"); roleLockTime[_role][_account] = block.timestamp + lockTime; _grantRole(_role, _account); @@ -267,7 +242,7 @@ contract SingleSidedInsurancePool is /** * @dev migrate user to new version */ - function migrate() external nonReentrant whenNotPaused isAlive { + function migrate() external nonReentrant whenNotPaused { require(migrateTo != address(0), "UnoRe: zero address"); _harvest(msg.sender); bool isUnLocked = block.timestamp - userInfo[msg.sender].lastWithdrawTime > lockTime; @@ -315,53 +290,33 @@ contract SingleSidedInsurancePool is * @dev stake user collateral, update user reward per block * @param _amount amount to deposit to pool */ - function enterInPool(uint256 _amount) external payable override whenNotPaused isAlive isStartTime nonReentrant { + function enterInPool(uint256 _amount) external payable override whenNotPaused isStartTime nonReentrant { _depositIn(_amount); _enterInPool(_amount, msg.sender); emit StakedInPool(msg.sender, riskPool, _amount); } - /** - * @dev WR will be in pending for 10 days at least - */ - function leaveFromPoolInPending(uint256 _amount) external override whenNotPaused isStartTime nonReentrant { - _harvest(msg.sender); - require(ICapitalAgent(capitalAgent).checkCapitalByMLR(address(this), _amount), "UnoRe: minimum capital underflow"); - // Withdraw desired amount from pool - uint256 amount = userInfo[msg.sender].amount; - uint256 lpPriceUno = IRiskPool(riskPool).lpPriceUno(); - (uint256 pendingAmount, , ) = IRiskPool(riskPool).getWithdrawRequest(msg.sender); - require(amount - pendingAmount >= (_amount * 1e18) / lpPriceUno, "UnoRe: withdraw amount overflow"); - IRiskPool(riskPool).leaveFromPoolInPending(msg.sender, _amount); - - userInfo[msg.sender].lastWithdrawTime = block.timestamp; - //As user is starting the withdraw we add the value to pending capital - ICapitalAgent(capitalAgent).updatePoolWithdrawPendingCapital(address(this), _amount, true); - emit LeftPool(msg.sender, riskPool, _amount); - } - /** * @dev user can submit claim again and receive his funds into his wallet after 10 days since last WR. */ - function leaveFromPending(uint256 _amount) external override isStartTime whenNotPaused nonReentrant { - require(_amount > 0, "Withdraw amount should be greator than zero"); - require(block.timestamp - userInfo[msg.sender].lastWithdrawTime >= lockTime, "UnoRe: Locked time"); + function withdraw(uint256 _amount) external override isStartTime whenNotPaused nonReentrant { + require(_amount > 0, "Unore: Withdraw amount should be greator than zero"); + require(userInfo[msg.sender].amount >= _amount, "Unore: Not enough funds"); _harvest(msg.sender); uint256 amount = userInfo[msg.sender].amount; - (uint256 withdrawAmount, uint256 withdrawAmountInUNO) = IRiskPool(riskPool).leaveFromPending(msg.sender, _amount); + (uint256 lpWithdrawAmount, uint256 tokenWithdrawAmount) = IRiskPool(riskPool).withdraw(msg.sender, _amount); - //As user is finishing the withdraw we subtract the value of pending capital (done inside SSIPWithdraw) - ICapitalAgent(capitalAgent).SSIPWithdraw(withdrawAmountInUNO); + ICapitalAgent(capitalAgent).SSIPWithdraw(tokenWithdrawAmount); uint256 accumulatedUno = (amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION; userInfo[msg.sender].rewardDebt = accumulatedUno - - ((withdrawAmount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION); + ((lpWithdrawAmount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION); - userInfo[msg.sender].amount = amount - withdrawAmount; + userInfo[msg.sender].amount = amount - lpWithdrawAmount; - emit LogLeaveFromPendingSSIP(msg.sender, riskPool, withdrawAmount, withdrawAmountInUNO); + emit LogWithdrawSSIP(msg.sender, riskPool, lpWithdrawAmount, tokenWithdrawAmount); } // Withdraw without caring about rewards. EMERGENCY ONLY. @@ -375,12 +330,11 @@ contract SingleSidedInsurancePool is emit EmergencyWithdraw(msg.sender, amount); } - function lpTransfer(address _from, address _to, uint256 _amount) external override nonReentrant whenNotPaused isAlive { + function lpTransfer(address _from, address _to, uint256 _amount) external override nonReentrant whenNotPaused { require(msg.sender == address(riskPool), "UnoRe: not allow others transfer"); _harvest(_from); uint256 amount = userInfo[_from].amount; - (uint256 pendingAmount, , ) = IRiskPool(riskPool).getWithdrawRequest(_from); - require(amount - pendingAmount >= _amount, "UnoRe: balance overflow"); + require(amount >= _amount, "UnoRe: balance overflow"); uint256 accumulatedUno = (amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION; userInfo[_from].rewardDebt = accumulatedUno - ((_amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION); userInfo[_from].amount = amount - _amount; @@ -395,7 +349,7 @@ contract SingleSidedInsurancePool is * @dev withdraw user pending uno * @param _to user address */ - function harvest(address _to) external override whenNotPaused isAlive isStartTime nonReentrant { + function harvest(address _to) external override whenNotPaused isStartTime nonReentrant { _harvest(_to); } @@ -421,7 +375,7 @@ contract SingleSidedInsurancePool is /** * @dev user roll over its pending uno to stake */ - function rollOverReward(address[] memory _to) external isStartTime whenNotPaused isAlive onlyRole(BOT_ROLE) nonReentrant { + function rollOverReward(address[] memory _to) external isStartTime whenNotPaused onlyRole(BOT_ROLE) nonReentrant { require(IRiskPool(riskPool).currency() == IRewarder(rewarder).currency(), "UnoRe: currency not matched"); updatePool(); uint256 _totalPendingUno; @@ -441,19 +395,6 @@ contract SingleSidedInsurancePool is emit RollOverReward(_to, riskPool, _totalPendingUno); } - /** - * @dev user can cancel its pending withdraw request - */ - function cancelWithdrawRequest() external nonReentrant whenNotPaused isAlive { - (uint256 cancelAmount, uint256 cancelAmountInUno) = IRiskPool(riskPool).cancelWithdrawRequest(msg.sender); - - //if user return the pending value into staking again by canceling withdraw, - //we remove the amount from the pending capital - ICapitalAgent(capitalAgent).updatePoolWithdrawPendingCapital(address(this), cancelAmount, false); - - emit LogCancelWithdrawRequest(msg.sender, cancelAmount, cancelAmountInUno); - } - /** * @dev return user staked currency corresponding to current lp price of uno */ @@ -463,24 +404,6 @@ contract SingleSidedInsurancePool is unoAmount = (lpAmount * lpPriceUno) / 1e18; } - /** - * @dev get withdraw request amount in pending per user in UNO - */ - function getWithdrawRequestPerUser( - address _user - ) external view returns (uint256 pendingAmount, uint256 pendingAmountInUno, uint256 originUnoAmount, uint256 requestTime) { - uint256 lpPriceUno = IRiskPool(riskPool).lpPriceUno(); - (pendingAmount, requestTime, originUnoAmount) = IRiskPool(riskPool).getWithdrawRequest(_user); - pendingAmountInUno = (pendingAmount * lpPriceUno) / 1e18; - } - - /** - * @dev get total withdraw request amount in pending for the risk pool in UNO - */ - function getTotalWithdrawPendingAmount() external view returns (uint256) { - return IRiskPool(riskPool).getTotalWithdrawRequestAmount(); - } - /** * @dev claim policy to payout, can only be called by claim processor role */ @@ -488,7 +411,7 @@ contract SingleSidedInsurancePool is uint256 _policyId, address _payout, uint256 _amount - ) public whenNotPaused isAlive onlyRole(CLAIM_PROCESSOR_ROLE) roleLockTimePassed(CLAIM_PROCESSOR_ROLE) { + ) public whenNotPaused onlyRole(CLAIM_PROCESSOR_ROLE) roleLockTimePassed(CLAIM_PROCESSOR_ROLE) { uint256 realClaimAmount = IRiskPool(riskPool).policyClaim(_payout, _amount); ICapitalAgent(capitalAgent).SSIPPolicyCaim(realClaimAmount, uint256(_policyId), true); @@ -522,14 +445,14 @@ contract SingleSidedInsurancePool is function grantRole( bytes32 role, address account - ) public override isAlive whenNotPaused onlyRole(getRoleAdmin(role)) roleLockTimePassed(getRoleAdmin(role)) { + ) public override whenNotPaused onlyRole(getRoleAdmin(role)) roleLockTimePassed(getRoleAdmin(role)) { _grantRole(role, account); } function _revokeRole( bytes32 role, address account - ) internal override isAlive whenNotPaused roleLockTimePassed(getRoleAdmin(role)) returns (bool) { + ) internal override whenNotPaused roleLockTimePassed(getRoleAdmin(role)) returns (bool) { return super._revokeRole(role, account); } @@ -549,12 +472,6 @@ contract SingleSidedInsurancePool is } function _updateReward(address _to) internal returns (uint256, uint256) { - uint256 requestTime; - (, requestTime, ) = IRiskPool(riskPool).getWithdrawRequest(_to); - if (requestTime > 0) { - return (0, 0); - } - uint256 amount = userInfo[_to].amount; uint256 accumulatedUno = (amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION; uint256 _pendingUno = accumulatedUno - userInfo[_to].rewardDebt; diff --git a/contracts/SingleSidedReinsurancePool.sol b/contracts/SingleSidedReinsurancePool.sol index f59a0372..90daba76 100644 --- a/contracts/SingleSidedReinsurancePool.sol +++ b/contracts/SingleSidedReinsurancePool.sol @@ -11,11 +11,12 @@ import "./interfaces/IMigration.sol"; import "./interfaces/IRiskPoolFactory.sol"; import "./interfaces/IRewarderFactory.sol"; import "./interfaces/ISingleSidedReinsurancePool.sol"; -import "./interfaces/ISyntheticSSRPFactory.sol"; +import "./deprecated/ISyntheticSSRPFactory.sol"; import "./interfaces/IRewarder.sol"; import "./interfaces/IRiskPool.sol"; import "./libraries/TransferHelper.sol"; +// TODO UPDATE THIS CONTRACT BASED ON CHANGES MADE ON SSIP contract SingleSidedReinsurancePool is ISingleSidedReinsurancePool, ReentrancyGuardUpgradeable, @@ -313,8 +314,7 @@ contract SingleSidedReinsurancePool is // Withdraw desired amount from pool uint256 amount = userInfo[msg.sender].amount; uint256 lpPriceUno = IRiskPool(riskPool).lpPriceUno(); - (uint256 pendingAmount, , ) = IRiskPool(riskPool).getWithdrawRequest(msg.sender); - require(amount - pendingAmount >= (_amount * 1e18) / lpPriceUno, "UnoRe: withdraw amount overflow"); + require(amount >= (_amount * 1e18) / lpPriceUno, "UnoRe: withdraw amount overflow"); IRiskPool(riskPool).leaveFromPoolInPending(msg.sender, _amount); userInfo[msg.sender].lastWithdrawTime = block.timestamp; @@ -345,8 +345,7 @@ contract SingleSidedReinsurancePool is if (_from != syntheticSSRP && _to != syntheticSSRP) { _harvest(_from); uint256 amount = userInfo[_from].amount; - (uint256 pendingAmount, , ) = IRiskPool(riskPool).getWithdrawRequest(_from); - require(amount - pendingAmount >= _amount, "UnoRe: balance overflow"); + require(amount >= _amount, "UnoRe: balance overflow"); uint256 accumulatedUno = (amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION; userInfo[_from].rewardDebt = accumulatedUno - ((_amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION); userInfo[_from].amount = amount - _amount; @@ -455,24 +454,6 @@ contract SingleSidedReinsurancePool is unoAmount = (lpAmount * lpPriceUno) / 1e18; } - /** - * @dev get withdraw request amount in pending per user in UNO - */ - function getWithdrawRequestPerUser( - address _user - ) external view returns (uint256 pendingAmount, uint256 pendingAmountInUno, uint256 originUnoAmount, uint256 requestTime) { - uint256 lpPriceUno = IRiskPool(riskPool).lpPriceUno(); - (pendingAmount, requestTime, originUnoAmount) = IRiskPool(riskPool).getWithdrawRequest(_user); - pendingAmountInUno = (pendingAmount * lpPriceUno) / 1e18; - } - - /** - * @dev get total withdraw request amount in pending for the risk pool in UNO - */ - function getTotalWithdrawPendingAmount() external view returns (uint256) { - return IRiskPool(riskPool).getTotalWithdrawRequestAmount(); - } - function setUserDetails( address _user, uint256 _amount, @@ -515,12 +496,6 @@ contract SingleSidedReinsurancePool is } function _updateReward(address _to) internal returns (uint256, uint256) { - uint256 requestTime; - (, requestTime, ) = IRiskPool(riskPool).getWithdrawRequest(_to); - if (requestTime > 0) { - return (0,0); - } - uint256 amount = userInfo[_to].amount; uint256 accumulatedUno = (amount * uint256(poolInfo.accUnoPerShare)) / ACC_UNO_PRECISION; uint256 _pendingUno = accumulatedUno - userInfo[_to].rewardDebt; diff --git a/contracts/interfaces/ISyntheticSSIP.sol b/contracts/deprecated/ISyntheticSSIP.sol similarity index 100% rename from contracts/interfaces/ISyntheticSSIP.sol rename to contracts/deprecated/ISyntheticSSIP.sol diff --git a/contracts/interfaces/ISyntheticSSIPFactory.sol b/contracts/deprecated/ISyntheticSSIPFactory.sol similarity index 100% rename from contracts/interfaces/ISyntheticSSIPFactory.sol rename to contracts/deprecated/ISyntheticSSIPFactory.sol diff --git a/contracts/interfaces/ISyntheticSSRP.sol b/contracts/deprecated/ISyntheticSSRP.sol similarity index 100% rename from contracts/interfaces/ISyntheticSSRP.sol rename to contracts/deprecated/ISyntheticSSRP.sol diff --git a/contracts/interfaces/ISyntheticSSRPFactory.sol b/contracts/deprecated/ISyntheticSSRPFactory.sol similarity index 100% rename from contracts/interfaces/ISyntheticSSRPFactory.sol rename to contracts/deprecated/ISyntheticSSRPFactory.sol diff --git a/contracts/SyntheticSSIP.sol b/contracts/deprecated/SyntheticSSIP.sol similarity index 98% rename from contracts/SyntheticSSIP.sol rename to contracts/deprecated/SyntheticSSIP.sol index 5079114f..bca1d782 100644 --- a/contracts/SyntheticSSIP.sol +++ b/contracts/deprecated/SyntheticSSIP.sol @@ -5,11 +5,11 @@ pragma solidity =0.8.23; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; -import "./interfaces/IMigration.sol"; -import "./interfaces/IRewarderFactory.sol"; -import "./interfaces/ISyntheticSSIP.sol"; -import "./interfaces/IRewarder.sol"; -import "./libraries/TransferHelper.sol"; +import "../interfaces/IMigration.sol"; +import "../interfaces/IRewarderFactory.sol"; +import "./ISyntheticSSIP.sol"; +import "../interfaces/IRewarder.sol"; +import "../libraries/TransferHelper.sol"; contract SyntheticSSIP is ISyntheticSSIP, ReentrancyGuard, AccessControl, Pausable { bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); diff --git a/contracts/factories/SyntheticSSIPFactory.sol b/contracts/deprecated/SyntheticSSIPFactory.sol similarity index 83% rename from contracts/factories/SyntheticSSIPFactory.sol rename to contracts/deprecated/SyntheticSSIPFactory.sol index 3e944f1c..095fdba3 100644 --- a/contracts/factories/SyntheticSSIPFactory.sol +++ b/contracts/deprecated/SyntheticSSIPFactory.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.23; -import "../SyntheticSSIP.sol"; -import "../interfaces/ISyntheticSSIPFactory.sol"; +import "./SyntheticSSIP.sol"; +import "./ISyntheticSSIPFactory.sol"; contract SyntheticSSIPFactory is ISyntheticSSIPFactory { constructor() {} diff --git a/contracts/SyntheticSSRP.sol b/contracts/deprecated/SyntheticSSRP.sol similarity index 98% rename from contracts/SyntheticSSRP.sol rename to contracts/deprecated/SyntheticSSRP.sol index b5950d7c..4eaf51ea 100644 --- a/contracts/SyntheticSSRP.sol +++ b/contracts/deprecated/SyntheticSSRP.sol @@ -5,11 +5,11 @@ pragma solidity =0.8.23; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; -import "./interfaces/IMigration.sol"; -import "./interfaces/IRewarderFactory.sol"; -import "./interfaces/ISyntheticSSRP.sol"; -import "./interfaces/IRewarder.sol"; -import "./libraries/TransferHelper.sol"; +import "../interfaces/IMigration.sol"; +import "../interfaces/IRewarderFactory.sol"; +import "./ISyntheticSSRP.sol"; +import "../interfaces/IRewarder.sol"; +import "../libraries/TransferHelper.sol"; contract SyntheticSSRP is ISyntheticSSRP, ReentrancyGuard, AccessControl, Pausable { bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); diff --git a/contracts/factories/SyntheticSSRPFactory.sol b/contracts/deprecated/SyntheticSSRPFactory.sol similarity index 83% rename from contracts/factories/SyntheticSSRPFactory.sol rename to contracts/deprecated/SyntheticSSRPFactory.sol index 8f6c40e3..76d9be74 100644 --- a/contracts/factories/SyntheticSSRPFactory.sol +++ b/contracts/deprecated/SyntheticSSRPFactory.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.23; -import "../SyntheticSSRP.sol"; -import "../interfaces/ISyntheticSSRPFactory.sol"; +import "./SyntheticSSRP.sol"; +import "./ISyntheticSSRPFactory.sol"; contract SyntheticSSRPFactory is ISyntheticSSRPFactory { constructor() {} diff --git a/contracts/interfaces/ICapitalAgent.sol b/contracts/interfaces/ICapitalAgent.sol index 52125c8f..618567f9 100644 --- a/contracts/interfaces/ICapitalAgent.sol +++ b/contracts/interfaces/ICapitalAgent.sol @@ -26,7 +26,7 @@ interface ICapitalAgent { function exchangeAgent() external view returns (address); - function getPoolInfo(address _pool) external view returns (uint256, address, bool, uint256); + function getPoolInfo(address _pool) external view returns (uint256, address, bool); function updatePoolWithdrawPendingCapital(address _pool, uint256 _amount, bool) external; } diff --git a/contracts/interfaces/IRiskPool.sol b/contracts/interfaces/IRiskPool.sol index b178d720..7676ae82 100644 --- a/contracts/interfaces/IRiskPool.sol +++ b/contracts/interfaces/IRiskPool.sol @@ -4,9 +4,7 @@ pragma solidity =0.8.23; interface IRiskPool { function enter(address _from, uint256 _amount) external; - function leaveFromPoolInPending(address _to, uint256 _amount) external; - - function leaveFromPending(address _to, uint256 _amount) external returns (uint256, uint256); + function withdraw(address _to, uint256 _amount) external returns (uint256,uint256); function cancelWithdrawRequest(address _to) external returns (uint256, uint256); @@ -18,10 +16,6 @@ interface IRiskPool { function currency() external view returns (address); - function getTotalWithdrawRequestAmount() external view returns (uint256); - - function getWithdrawRequest(address _to) external view returns (uint256, uint256, uint256); - function lpPriceUno() external view returns (uint256); function emergencyWithdraw(address _to, uint256 _amount) external returns (bool); diff --git a/contracts/uma/PayoutRequest.sol b/contracts/uma/PayoutRequest.sol index a166bc36..78818f32 100644 --- a/contracts/uma/PayoutRequest.sol +++ b/contracts/uma/PayoutRequest.sol @@ -242,7 +242,7 @@ contract PayoutRequest is PausableUpgradeable { uint256 _claimed = ICapitalAgent(capitalAgent).claimedAmount(salesPolicy, _policyId); (uint256 _coverageAmount, , , bool _exist, bool _expired) = ISalesPolicy(salesPolicy).getPolicyData(_policyId); address _exchangeAgent = ICapitalAgent(capitalAgent).exchangeAgent(); - (,address _currency, , ) = ICapitalAgent(capitalAgent).getPoolInfo(address(ssip)); + (,address _currency, ) = ICapitalAgent(capitalAgent).getPoolInfo(address(ssip)); address _usdcToken = IExchangeAgent(_exchangeAgent).usdcToken(); uint256 usdcTokenAmount = IExchangeAgent(_exchangeAgent).getNeededTokenAmount(_currency, _usdcToken, _amount); // @Audit: there might be a chance of amount loss due to precision loss require(usdcTokenAmount + _claimed <= _coverageAmount, "UnoRe: amount exceeds coverage amount"); diff --git a/test/UnoV3/PremiumPoolAndSalesPolicyTest.t.sol b/test/UnoV3/PremiumPoolAndSalesPolicyTest.t.sol index 24352b85..eb13710f 100644 --- a/test/UnoV3/PremiumPoolAndSalesPolicyTest.t.sol +++ b/test/UnoV3/PremiumPoolAndSalesPolicyTest.t.sol @@ -434,14 +434,6 @@ contract PremiumPoolAndSalesPolicyTest is Test { vm.stopPrank(); } - function testDepositToSyntheticSSRPRewarder() public { - // TODO: VERIFY IF THIS IS NECESSARY Implement test for depositToSyntheticSSRPRewarder function - } - - function testDepositToSyntheticSSIPRewarder() public { - // TODO: VERIFY IF THIS IS NECESSARY Implement test for depositToSyntheticSSIPRewarder function - } - function testBuyBackAndBurn() public { address user = address(0x1234); uint256 initialDeposit = 1000 ether;