Withdraw from a supply pool
The aaveWithdrawAsset data slice provides a re-usable Alpine.js data slice for enabling the current user to withdraw their asset from the Aave pool via the withdraw() 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 the asset to withdraw from the pool. Defaults to
0. Set or update it in the markup withx-bind,x-init, orx-data.
token
- Type: Object or Undefined
- Description: Reserve asset information the user wishes to withdraw. 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
undefinedand is defined within thewithdrawAssetfunction.
Methods
The aaveWithdrawAsset data slice provides the following method:
withdrawAsset(): Promise<void>
This method allows the current user to withdraw their underlying asset from an Aave V3 pool via the withdraw() contract method.
Parameters:
args.amount- (Optional) Amount of reserve asset to withdraw.args.reserve- (Optional) Token the user wishes to withdraw from the supply pool.
Example
The snippet below showcases a simple implementation of a widget that allows the user to withdraw their DAI for the supply pool.
<section x-data="aaveWithdrawAsset" x-init="`" market="DAI" ; token="$aaveAssetBySymbol(market);" amount="1;" userAssetData="$store.currentUser?.aavePortfolio?.summary.userReservesData.filter(reserve" =""> token.UNDERLYING.toLowerCase() === reserve.underlyingAsset.toLowerCase())[0]; ` > <form @submit.prevent="withdrawAsset()"> <div> <label for="withdraw">Amount to withdraw</label> <input x-model.number="amount" min="0.000001" id="withdraw" type="number" placeholder="1.00" step="0.000001" /> <button>Withdraw</button> </div> <span x-text="status"></span> </form></section>