Repaying debt
The aaveRepayDebt
data slice provides a re-usable Alpine.js data slice for enabling the current user to repay their debt via either the repayWithPermit()
or repayWithATokens()
contract methods.
Data Slice Structure
status
- Type: String
- Description: Represents the status of the contract write request. Can be
'idle'
,'signaturePending'
,'transactionPending'
,'transactionSuccessful'
, or'error'
. Defaults to'idle'
.
amount
- Type: Number
- Description: Amount spent on repaying the debt. Defaults to
0
. Set or update it in the markup withx-bind
,x-init
, orx-data
.
interestRateMode
- Type: Enumeration (InterestRate)
- Description: Borrow rate mode. Defaults to variable. Set in the markup.
token
- Type: Object or Undefined
- Description: Reserve asset information the user wishes to borrow. Defaults to
undefined
. Set or update it in the markup withx-bind
,x-init
, orx-data
.
txsHashes
- Type: Any
- Description: Hash(es) of the transactions. Defaults to
undefined
and is defined within therepayDebt
function.
Methods
The aaveRepayDebt
data slice provides the following methods:
repayDebt(args: { onBehalfOfAddress?: string }): Promise<void>
This method allows the current user to repay their debt via the repayWithPermit()
contract method. The user must have a collateralized position (hold a positive balance of aToken in their wallet), or the method will fail.
Parameters:
args.amount
- (Optional) Amount of tokens used to repay the debt.args.reserve
- (Optional) Reserve from which the user wishes to borrow.
repayDebtWithAToken(): Promise<void>
This method allows the current user to repay their debt via the repayWithATokens()
contract method.
Example
The snippet below showcases a simple implementation of a widget that allows the user to repay their GHO against debt using their GHO balance.