Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ethereumdegen committed Aug 28, 2024
1 parent 769f1a3 commit d35939d
Showing 1 changed file with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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(

Expand Down Expand Up @@ -445,7 +454,7 @@ contract LenderCommitmentGroup_Smart is
uint256 _collateralTokenId,
uint32 _loanDuration,
uint16 _interestRate
) external onlySmartCommitmentForwarder whenNotPaused {
) external onlySmartCommitmentForwarder whenForwarderNotPaused {

require(
_collateralTokenAddress == address(collateralToken),
Expand Down Expand Up @@ -505,32 +514,40 @@ 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;
}



/*
*/
function burnSharesToWithdrawEarnings(
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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit d35939d

Please sign in to comment.