From d35939d0218708173c2c48409e3ae0d580024a37 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 28 Aug 2024 11:19:33 -0400 Subject: [PATCH 1/2] clean up --- .../LenderCommitmentGroup_Smart.sol | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) 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(); From 6d7e2717b3378c418180bb49de9fb24610ab31e3 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 28 Aug 2024 11:27:01 -0400 Subject: [PATCH 2/2] remove code from other pr --- .../LenderCommitmentGroup_Smart.sol | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol b/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol index c8b596d2..d1252ddb 100644 --- a/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol +++ b/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol @@ -210,13 +210,6 @@ 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, @@ -381,7 +374,7 @@ contract LenderCommitmentGroup_Smart is uint256 _amount, address _sharesRecipient, uint256 _minSharesAmountOut - ) external whenForwarderNotPaused returns (uint256 sharesAmount_) { + ) external returns (uint256 sharesAmount_) { //transfers the primary principal token from msg.sender into this contract escrow @@ -407,7 +400,8 @@ contract LenderCommitmentGroup_Smart is //mint shares equal to _amount and give them to the shares recipient !!! poolSharesToken.mint(_sharesRecipient, sharesAmount_); - + + // prepare current balance uint256 sharesBalance = poolSharesToken.balanceOf(address(this)); @@ -454,7 +448,7 @@ contract LenderCommitmentGroup_Smart is uint256 _collateralTokenId, uint32 _loanDuration, uint16 _interestRate - ) external onlySmartCommitmentForwarder whenForwarderNotPaused { + ) external onlySmartCommitmentForwarder whenNotPaused { require( _collateralTokenAddress == address(collateralToken), @@ -514,12 +508,10 @@ contract LenderCommitmentGroup_Smart is function prepareSharesForWithdraw( uint256 _amountPoolSharesTokens - ) external whenForwarderNotPaused returns (bool) { - + ) external returns (bool) { return _prepareSharesForWithdraw(_amountPoolSharesTokens); } - function _prepareSharesForWithdraw( uint256 _amountPoolSharesTokens ) internal returns (bool) { @@ -532,7 +524,6 @@ contract LenderCommitmentGroup_Smart is } - /* */ @@ -540,14 +531,14 @@ contract LenderCommitmentGroup_Smart is uint256 _amountPoolSharesTokens, address _recipient, uint256 _minAmountOut - ) external whenForwarderNotPaused returns (uint256) { + ) external 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] = block.timestamp; + poolSharesPreparedTimestamp[msg.sender] = block.timestamp; //this should compute BEFORE shares burn @@ -583,7 +574,7 @@ contract LenderCommitmentGroup_Smart is function liquidateDefaultedLoanWithIncentive( uint256 _bidId, int256 _tokenAmountDifference - ) public whenForwarderNotPaused bidIsActiveForGroup(_bidId) { + ) public bidIsActiveForGroup(_bidId) { //use original principal amount as amountDue @@ -880,7 +871,7 @@ contract LenderCommitmentGroup_Smart is address repayer, uint256 principalAmount, uint256 interestAmount - ) external onlyTellerV2 whenForwarderNotPaused { + ) external onlyTellerV2 { //can use principal amt to increment amt paid back!! nice for math . totalPrincipalTokensRepaid += principalAmount; totalInterestCollected += interestAmount; @@ -900,7 +891,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 whenForwarderNotPaused { + function withdrawFromEscrowVault ( uint256 _amount ) public { address _escrowVault = ITellerV2(TELLER_V2).getEscrowVault();