Borrowing liquidity from a pool
The aaveBorrowReserveAsset
data slice provides a re-usable Alpine.js data slice for enabling the current user to borrow a reserve asset from an Aave V3 pool using the borrow()
contract method.
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 of reserve asset to borrow from the pool. Defaults to
0
. Set or update it in the markup withx-bind
,x-init
, orx-data
.
interestRateMode
- Type: Enum (
InterestRate
) - Description: Interest rate mode. Defaults to
InterestRateMode.None
.
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 theborrowReserveAsset
function.
Methods
The aaveBorrowReserveAsset
data slice provides the following method:
borrow(): Promise<void>
- This method allows the current user to borrow assets from an Aave V3 pool using the
borrow()
contract method. The user must have a collateralized position (hold a positive balance of aToken in their wallet) for the method to succeed. - Parameters:
amount
: (Optional) Amount of reserve asset to borrow.reserve
: (Optional) Object with properties{ UNDERLYING: string, decimals: number }
representing the reserve from which the user wishes to borrow.
- Returns: A Promise that resolves when the transaction is successful and rejects on error.
- This method allows the current user to borrow assets from an Aave V3 pool using the
Additional Information
- The user must have a collateralized position (hold a positive balance of aToken in their wallet) for the
borrow()
method to succeed. - Aave Utilities Documentation on Borrow
Example
The snippet below showcases a simple implementation of a widget that allows the user to borrow GHO against their collateral.