This function allows borrowers to repay their debt.
There are 3 types of repay, with gradual complexity, each incrementally applied based on how the debt associated to the requested repay is distributed:
  • Soft repay: if your debt is not matched in peer-to-peer, it will be repaid to the underlying protocol's pool.
  • Transfer repay: if your debt is matched in peer-to-peer, your debt will be replaced with other unmatched borrowers' debt.
  • Hard repay: if Morpho can't find enough unmatched debt, Morpho unmatches the suppliers you are matched with, within the gas consumption limit set by governance. If not enough debt is unmatched, the remaining debt repaid is supplied to the underlying pool and a spread will get introduced to Morpho's supply peer-to-peer supply rate to compensate, until the extra liquidity is matched with a new borrower (this mechanism corresponds to the delta mechanism further described here).
Repayers must approve the Morpho contract to spend _amount of the underlying ERC20 token.
A user cannot repay more than their debt: the input amount will be cropped to the maximum amount that can be repaid (the debt value of the user on the given market).
function repay(
address _poolTokenAddress,
address _onBehalf,
uint256 _amount
Input parameter
Input type
The address of the underlying protocol's pool token to repay to.
The address of the borrower who will benefit from the repaid amount. In most cases, you want to repay to yourself: _onBehalf === msg.sender
The amount of underlying ERC20 tokens to repay.
Emitted Events