|
| 1 | +# Aave V3 borrow workflow |
| 2 | + |
| 3 | +Use this workflow to borrow assets from Aave V3 against supplied collateral. |
| 4 | + |
| 5 | +## Flow |
| 6 | + |
| 7 | +1. Resolve chain, asset address, and pool address. |
| 8 | +2. Check collateral and borrow capacity. |
| 9 | +3. Preview health factor impact. |
| 10 | +4. Query the Aave API for the borrow transaction and execute. |
| 11 | + |
| 12 | +## Resolve chain and addresses |
| 13 | + |
| 14 | +If the user doesn't specify a chain, ask. Look up the pool address: |
| 15 | + |
| 16 | +| Chain | Chain ID | Pool address | |
| 17 | +| --- | --- | --- | |
| 18 | +| Ethereum | 1 | `0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2` | |
| 19 | +| Polygon | 137 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` | |
| 20 | +| Arbitrum | 42161 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` | |
| 21 | +| Optimism | 10 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` | |
| 22 | +| Avalanche | 43114 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` | |
| 23 | +| Base | 8453 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` | |
| 24 | + |
| 25 | +## Check collateral |
| 26 | + |
| 27 | +Before borrowing, check the user's positions using `aave-positions.md`. Verify the following. |
| 28 | + |
| 29 | +1. The user has supplied collateral. If not, follow `aave-supply.md` to supply assets first. |
| 30 | +2. Collateral is enabled on at least one supplied asset (`isCollateral` is `true`). If not, follow `aave-collateral.md` to enable it. |
| 31 | +3. Available borrow capacity covers the requested amount. |
| 32 | + |
| 33 | +Query available markets to check the target asset's borrow APY and whether `borrowCapReached` is `true`. See `aave-markets.md`. |
| 34 | + |
| 35 | +## Preview health factor |
| 36 | + |
| 37 | +Preview the health factor impact before borrowing: |
| 38 | + |
| 39 | +```bash |
| 40 | +curl -s -X POST https://api.v3.aave.com/graphql \ |
| 41 | + -H 'Content-Type: application/json' \ |
| 42 | + -d '{ |
| 43 | + "query": "{ healthFactorPreview(request: { action: { borrow: { market: \"<POOL_ADDRESS>\", sender: \"<WALLET_ADDRESS>\", chainId: <CHAIN_ID>, amount: { erc20: { currency: \"<ASSET_ADDRESS>\", value: \"<AMOUNT>\" } } } } }) { before after } }" |
| 44 | + }' |
| 45 | +``` |
| 46 | + |
| 47 | +Show the health factor before and after. If the projected health factor (`after`) drops below 1.5, warn about liquidation risk. If it drops below 1.0, stop and tell the user to reduce the borrow amount or repay existing debt. |
| 48 | + |
| 49 | +## Query borrow transaction |
| 50 | + |
| 51 | +Get the wallet address and query the Aave V3 GraphQL API. Don't include `onBehalfOf` when borrowing for the user's own account. It triggers a credit delegation requirement even for self-borrows. |
| 52 | + |
| 53 | +```bash |
| 54 | +mm wallet address |
| 55 | +``` |
| 56 | + |
| 57 | +```bash |
| 58 | +curl -s -X POST https://api.v3.aave.com/graphql \ |
| 59 | + -H 'Content-Type: application/json' \ |
| 60 | + -d '{ |
| 61 | + "query": "{ borrow(request: { market: \"<POOL_ADDRESS>\", amount: { erc20: { currency: \"<ASSET_ADDRESS>\", value: \"<AMOUNT>\" } }, sender: \"<WALLET_ADDRESS>\", chainId: <CHAIN_ID> }) { __typename ... on TransactionRequest { to from data value chainId } ... on ApprovalRequired { approval { to from data value chainId } originalTransaction { to from data value chainId } } ... on InsufficientBalanceError { required { value decimals } available { value decimals } } } }" |
| 62 | + }' |
| 63 | +``` |
| 64 | + |
| 65 | +The `value` in the amount is a human-readable decimal string (e.g., `"2"`, `"100"`). The API handles conversion. |
| 66 | + |
| 67 | +## Execute borrow |
| 68 | + |
| 69 | +Confirm the asset, amount, chain, and projected health factor with the user. The `value` field must be `0x`-prefixed hex (typically `"0x0"` for ERC-20 borrows). |
| 70 | + |
| 71 | +```bash |
| 72 | +mm wallet send-transaction --chain-id <CHAIN_ID> --payload '{"to":"<TO>","value":"0x0","data":"<DATA>"}' --wait --intent "Borrow <AMOUNT> <SYMBOL> from Aave V3 on <CHAIN_NAME>" |
| 73 | +``` |
| 74 | + |
| 75 | +If the response is `InsufficientBalanceError`, show the required and available amounts and stop. |
| 76 | + |
| 77 | +## Notes |
| 78 | + |
| 79 | +- After the transaction confirms, use `aave-positions.md` to verify the updated position and health factor. |
| 80 | +- The borrowed amount accrues interest over time. Check debt at any time using `aave-positions.md`. |
| 81 | +- To repay the borrow, see `aave-repay.md`. |
0 commit comments