Skip to content

Instantly share code, notes, and snippets.

@prajwolrg
Created August 9, 2022 08:57
Show Gist options
  • Save prajwolrg/637ce93c72ddc2e3d9cf8f8dd986b76a to your computer and use it in GitHub Desktop.
Save prajwolrg/637ce93c72ddc2e3d9cf8f8dd986b76a to your computer and use it in GitHub Desktop.
Repay
pragma solidity >=0.4.21 <0.7.0;
function repay(address _reserve, uint256 _amount)
external
onlyAmountGreaterThanZero(_amount)
{
(, uint256 currentBorrowBalance, , , ) = dataProvider.getUserReserveData(
_reserve,
msg.sender
);
uint256 amountToReturn = 0;
require(currentBorrowBalance > 0, "User does not have any borrow pending");
if (_amount > currentBorrowBalance) {
amountToReturn = _amount - currentBorrowBalance;
}
uint256 amountToRepay = _amount - amountToReturn;
// update state
core.updateStateOnRepay(_reserve, msg.sender, amountToRepay);
// return back to user
core.transferToUser(_reserve, msg.sender, amountToReturn);
// transfer required amount to core
core.transferToReserve(_reserve, msg.sender, amountToRepay);
emit Repay(_reserve, msg.sender, amountToRepay, block.timestamp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment