diff --git a/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol b/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol index 72481fbd..c8b596d2 100644 --- a/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol +++ b/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol @@ -210,6 +210,13 @@ contract LenderCommitmentGroup_Smart is _; } + modifier whenForwarderNotPaused() { + require( PausableUpgradeable(address(SMART_COMMITMENT_FORWARDER)).paused() == false , "Protocol is paused"); + _; + } + + + /// @custom:oz-upgrades-unsafe-allow constructor constructor( address _tellerV2, @@ -374,7 +381,7 @@ contract LenderCommitmentGroup_Smart is uint256 _amount, address _sharesRecipient, uint256 _minSharesAmountOut - ) external returns (uint256 sharesAmount_) { + ) external whenForwarderNotPaused returns (uint256 sharesAmount_) { //transfers the primary principal token from msg.sender into this contract escrow @@ -402,8 +409,10 @@ contract LenderCommitmentGroup_Smart is poolSharesToken.mint(_sharesRecipient, sharesAmount_); - //reset prepared amount - poolSharesPreparedToWithdrawForLender[msg.sender] = 0; + // prepare current balance + uint256 sharesBalance = poolSharesToken.balanceOf(address(this)); + _prepareSharesForWithdraw(sharesBalance); + emit LenderAddedPrincipal( @@ -445,7 +454,7 @@ contract LenderCommitmentGroup_Smart is uint256 _collateralTokenId, uint32 _loanDuration, uint16 _interestRate - ) external onlySmartCommitmentForwarder whenNotPaused { + ) external onlySmartCommitmentForwarder whenForwarderNotPaused { require( _collateralTokenAddress == address(collateralToken), @@ -505,17 +514,25 @@ contract LenderCommitmentGroup_Smart is function prepareSharesForWithdraw( uint256 _amountPoolSharesTokens - ) external returns (bool) { + ) external whenForwarderNotPaused returns (bool) { + + return _prepareSharesForWithdraw(_amountPoolSharesTokens); + } + + + function _prepareSharesForWithdraw( + uint256 _amountPoolSharesTokens + ) internal returns (bool) { require( poolSharesToken.balanceOf(msg.sender) >= _amountPoolSharesTokens ); poolSharesPreparedToWithdrawForLender[msg.sender] = _amountPoolSharesTokens; - poolSharesPreparedTimestamp[msg.sender] = block.timestamp; - + poolSharesPreparedTimestamp[msg.sender] = block.timestamp; return true; } + /* */ @@ -523,14 +540,14 @@ contract LenderCommitmentGroup_Smart is uint256 _amountPoolSharesTokens, address _recipient, uint256 _minAmountOut - ) external returns (uint256) { + ) external whenForwarderNotPaused returns (uint256) { require(poolSharesPreparedToWithdrawForLender[msg.sender] >= _amountPoolSharesTokens,"Shares not prepared for withdraw"); require(poolSharesPreparedTimestamp[msg.sender] <= block.timestamp - WITHDRAW_DELAY_TIME_SECONDS,"Shares not prepared for withdraw"); poolSharesPreparedToWithdrawForLender[msg.sender] = 0; - poolSharesPreparedTimestamp[msg.sender] = 0; + poolSharesPreparedTimestamp[msg.sender] = block.timestamp; //this should compute BEFORE shares burn @@ -566,7 +583,7 @@ contract LenderCommitmentGroup_Smart is function liquidateDefaultedLoanWithIncentive( uint256 _bidId, int256 _tokenAmountDifference - ) public bidIsActiveForGroup(_bidId) { + ) public whenForwarderNotPaused bidIsActiveForGroup(_bidId) { //use original principal amount as amountDue @@ -863,7 +880,7 @@ contract LenderCommitmentGroup_Smart is address repayer, uint256 principalAmount, uint256 interestAmount - ) external onlyTellerV2 { + ) external onlyTellerV2 whenForwarderNotPaused { //can use principal amt to increment amt paid back!! nice for math . totalPrincipalTokensRepaid += principalAmount; totalInterestCollected += interestAmount; @@ -883,7 +900,7 @@ contract LenderCommitmentGroup_Smart is If principaltokens get stuck in the escrow vault for any reason, anyone may call this function to move them from that vault in to this contract */ - function withdrawFromEscrowVault ( uint256 _amount ) public { + function withdrawFromEscrowVault ( uint256 _amount ) public whenForwarderNotPaused { address _escrowVault = ITellerV2(TELLER_V2).getEscrowVault();