Skip to content

Commit

Permalink
(Cache some reads)
Browse files Browse the repository at this point in the history
This reverts commit cb4185360d4f47f1e8ba5944fd1d9bd4221150e3.
  • Loading branch information
Barry Lyndon committed Jun 7, 2022
1 parent a71a60f commit 6624413
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions contracts/NFTPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,16 @@ contract NFTPair is BoringOwnable, Domain, IMasterContract {
// fits in 128 as it represents a BentoBox balance.
// Skimming is safe: the amount gets transferred to the lender later,
// and therefore cannot be skimmed twice.
IERC20 asset_ = asset;
if (skim) {
require(bentoBox.balanceOf(asset, address(this)) >= (totalShare + feesEarnedShare), "NFTPair: skim too much");
require(bentoBox.balanceOf(asset_, address(this)) >= (totalShare + feesEarnedShare), "NFTPair: skim too much");
} else {
bentoBox.transfer(asset, msg.sender, address(this), totalShare);
bentoBox.transfer(asset_, msg.sender, address(this), totalShare);
}
// No overflow: result fits in BentoBox
feesEarnedShare += feeShare;
// No underflow: `feeShare` is 10% of part of `totalShare`
bentoBox.transfer(asset, address(this), lender, totalShare - feeShare);
bentoBox.transfer(asset_, address(this), lender, totalShare - feeShare);
}

/// @notice Repay a loan in part or in full
Expand Down
7 changes: 4 additions & 3 deletions contracts/NFTPairWithOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,16 @@ contract NFTPairWithOracle is BoringOwnable, Domain, IMasterContract {
// fits in 128 as it represents a BentoBox balance.
// Skimming is safe: the amount gets transferred to the lender later,
// and therefore cannot be skimmed twice.
IERC20 asset_ = asset;
if (skim) {
require(bentoBox.balanceOf(asset, address(this)) >= (totalShare + feesEarnedShare), "NFTPair: skim too much");
require(bentoBox.balanceOf(asset_, address(this)) >= (totalShare + feesEarnedShare), "NFTPair: skim too much");
} else {
bentoBox.transfer(asset, msg.sender, address(this), totalShare);
bentoBox.transfer(asset_, msg.sender, address(this), totalShare);
}
// No overflow: result fits in BentoBox
feesEarnedShare += feeShare;
// No underflow: `feeShare` is 10% of part of `totalShare`
bentoBox.transfer(asset, address(this), lender, totalShare - feeShare);
bentoBox.transfer(asset_, address(this), lender, totalShare - feeShare);
}

/// @notice Repay a loan in part or in full
Expand Down

0 comments on commit 6624413

Please sign in to comment.