Skip to content

Instantly share code, notes, and snippets.

@dplamenov
Created August 27, 2022 14:40
Show Gist options
  • Save dplamenov/8b418e46bc355a51fb7c037722a0e61e to your computer and use it in GitHub Desktop.
Save dplamenov/8b418e46bc355a51fb7c037722a0e61e to your computer and use it in GitHub Desktop.
function repayLoan(ERC20 token_, uint256 amount_) external nonReentrant {
if (reserveDebt[token_][msg.sender] == 0) revert TRSRY_NoDebtOutstanding();
// Deposit from caller first (to handle nonstandard token transfers)
token_.safeTransferFrom(msg.sender, address(this), amount_);
// Subtract debt from caller
reserveDebt[token_][msg.sender] -= amount_;
totalDebt[token_] -= amount_;
emit DebtRepaid(token_, msg.sender, amount_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment