Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert for fee on transfer #65

Open
wants to merge 1 commit into
base: merge-train-r4-test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/contracts/contracts/CollateralManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ contract CollateralManager is OwnableUpgradeable, ICollateralManager {
escrowAddress
);
// Pull collateral from borrower & deposit into escrow
// This will revert with fee-on-transfer tokens
if (collateralInfo._collateralType == CollateralType.ERC20) {
IERC20Upgradeable(collateralInfo._collateralAddress).transferFrom(
borrower,
Expand Down
33 changes: 20 additions & 13 deletions packages/contracts/contracts/TellerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ contract TellerV2 is
);
}

//local stack scope
{
uint256 balanceBefore = bid.loanDetails.lendingToken.balanceOf(
address(bid.receiver)
);

//transfer funds to borrower
if (amountToBorrower > 0) {
bid.loanDetails.lendingToken.safeTransferFrom(
Expand All @@ -548,6 +554,16 @@ contract TellerV2 is
);
}

uint256 balanceAfter = bid.loanDetails.lendingToken.balanceOf(
address(bid.receiver)
);

//used to revert for fee-on-transfer tokens
uint256 paymentAmountReceived = balanceAfter - balanceBefore;
require(amountToBorrower == paymentAmountReceived, "UT");
}


// Record volume filled by lenders
lenderVolumeFilled[address(bid.loanDetails.lendingToken)][sender] += bid
.loanDetails
Expand Down Expand Up @@ -877,33 +893,24 @@ contract TellerV2 is
{} catch {
address sender = _msgSenderForMarket(bid.marketplaceId);

uint256 balanceBefore = bid.loanDetails.lendingToken.balanceOf(
address(this)
);


//if unable, pay to escrow
//fee-on-transfer tokens should not make it past the acceptBid step
bid.loanDetails.lendingToken.safeTransferFrom(
sender,
address(this),
_paymentAmount
);

uint256 balanceAfter = bid.loanDetails.lendingToken.balanceOf(
address(this)
);

//used for fee-on-send tokens
uint256 paymentAmountReceived = balanceAfter - balanceBefore;

bid.loanDetails.lendingToken.approve(
address(escrowVault),
paymentAmountReceived
_paymentAmount
);

IEscrowVault(escrowVault).deposit(
lender,
address(bid.loanDetails.lendingToken),
paymentAmountReceived
_paymentAmount
);
}

Expand Down