Skip to content

Commit bd31fef

Browse files
add aave v3 workflows
1 parent 64926f3 commit bd31fef

18 files changed

Lines changed: 1142 additions & 2 deletions

skills/metamask-agent-wallet/SKILL.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: metamask-agent-wallet
3-
description: Use when the user asks anything about blockchain wallets, transactions, signing, token transfers, supported chains, wallet balances, perpetual futures trading, prediction markets, token swaps, cross-chain bridges, market data, token discovery, decoding EVM calldata, or authentication via the MetaMask Agentic CLI. Single entry point for all mm CLI operations.
3+
description: Use when the user asks anything about blockchain wallets, transactions, signing, token transfers, supported chains, wallet balances, perpetual futures trading, prediction markets, token swaps, cross-chain bridges, market data, token discovery, decoding EVM calldata, Aave V3 lending and borrowing, or authentication via the MetaMask Agentic CLI. Single entry point for all mm CLI operations.
44
license: MIT
55
metadata:
66
author: metamask
@@ -111,6 +111,13 @@ CLI behavior lives in `references/`. Repeatable patterns live in `workflows/`. L
111111
| Modify a perpetual position flow | [perps-modify-position.md](workflows/perps-modify-position.md) |
112112
| Predict setup-fund-quote-place flow | [predict-trading.md](workflows/predict-trading.md) |
113113
| Token discovery, prices, and market data | [market-data.md](workflows/market-data.md) |
114+
| Supply assets to Aave V3 | [aave-supply.md](workflows/aave-supply.md) |
115+
| Withdraw assets from Aave V3 | [aave-withdraw.md](workflows/aave-withdraw.md) |
116+
| Borrow from Aave V3 | [aave-borrow.md](workflows/aave-borrow.md) |
117+
| Repay Aave V3 debt | [aave-repay.md](workflows/aave-repay.md) |
118+
| Toggle Aave V3 collateral | [aave-collateral.md](workflows/aave-collateral.md) |
119+
| Check Aave V3 positions and health factor | [aave-positions.md](workflows/aave-positions.md) |
120+
| Discover Aave V3 tokens, rates, and liquidity | [aave-markets.md](workflows/aave-markets.md) |
114121

115122
## Global Flags
116123

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
"""Convert a human-readable token amount to 0x-prefixed hex for EVM calldata.
3+
4+
Usage:
5+
python3 amount_to_hex.py <amount> <decimals>
6+
7+
Examples:
8+
python3 amount_to_hex.py 1.5 18 # 1.5 ETH -> 0x14d1120d7b160000
9+
python3 amount_to_hex.py 100 6 # 100 USDC -> 0x5f5e100
10+
python3 amount_to_hex.py 0.001 8 # 0.001 WBTC -> 0x186a0
11+
"""
12+
13+
import sys
14+
from decimal import Decimal
15+
16+
if len(sys.argv) != 3:
17+
print(f"Usage: {sys.argv[0]} <amount> <decimals>", file=sys.stderr)
18+
sys.exit(1)
19+
20+
decimals = int(sys.argv[2])
21+
value = int(Decimal(sys.argv[1]) * 10 ** decimals)
22+
23+
print(hex(value))
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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`.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Aave V3 collateral workflow
2+
3+
Use this workflow to enable or disable an asset as collateral on Aave V3.
4+
5+
## Flow
6+
7+
1. Resolve chain, asset address, and pool address.
8+
2. Check current collateral status and health factor.
9+
3. Query the Aave API for the collateral toggle transaction.
10+
4. Execute toggle.
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 status
26+
27+
Query the user's positions using `aave-positions.md`. For the target asset, check whether collateral is enabled or disabled (`isCollateral`).
28+
29+
The user must have a non-zero supply of the asset to toggle collateral.
30+
31+
When disabling collateral, check the health factor. If the user has outstanding borrows, disabling collateral lowers the health factor. Show the impact. If the health factor would drop below 1.0, stop and tell the user to repay debt first via `aave-repay.md`.
32+
33+
## Query collateral toggle transaction
34+
35+
Get the wallet address and query the Aave V3 GraphQL API:
36+
37+
```bash
38+
mm wallet address
39+
```
40+
41+
```bash
42+
curl -s -X POST https://api.v3.aave.com/graphql \
43+
-H 'Content-Type: application/json' \
44+
-d '{
45+
"query": "{ collateralToggle(request: { market: \"<POOL_ADDRESS>\", underlyingToken: \"<ASSET_ADDRESS>\", user: \"<WALLET_ADDRESS>\", chainId: <CHAIN_ID> }) { to from data value chainId } }"
46+
}'
47+
```
48+
49+
The API returns a `TransactionRequest` with `{to, from, data, value, chainId}`. The toggle direction is determined automatically based on the current collateral state.
50+
51+
## Execute toggle
52+
53+
Confirm the asset, toggle direction (enabling or disabling), and chain with the user. The `value` field must be `0x`-prefixed hex.
54+
55+
```bash
56+
mm wallet send-transaction --chain-id <CHAIN_ID> --payload '{"to":"<TO>","value":"0x0","data":"<DATA>"}' --wait --intent "Toggle <SYMBOL> as collateral on Aave V3 on <CHAIN_NAME>"
57+
```
58+
59+
## Notes
60+
61+
- Enabling collateral lets the asset back borrows, increasing borrow capacity.
62+
- Disabling collateral removes it from the borrow calculation. This may trigger liquidation if remaining collateral can't cover existing debt.
63+
- Not all assets support collateral usage. If the transaction reverts, the reserve may not be eligible.
64+
- After the transaction confirms, verify the updated status using `aave-positions.md`.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Aave V3 markets workflow
2+
3+
Use this workflow to discover available Aave V3 tokens, supply/borrow rates, and borrowing capacity on a chain.
4+
5+
## Flow
6+
7+
1. Resolve chain.
8+
2. Query available markets.
9+
3. Present results.
10+
11+
## Resolve chain
12+
13+
If the user doesn't specify a chain, ask. Aave V3 is deployed on these chains:
14+
15+
| Chain | Chain ID |
16+
| --- | --- |
17+
| Ethereum | 1 |
18+
| Polygon | 137 |
19+
| Arbitrum | 42161 |
20+
| Optimism | 10 |
21+
| Avalanche | 43114 |
22+
| Base | 8453 |
23+
24+
## Query available markets
25+
26+
```bash
27+
curl -s -X POST https://api.v3.aave.com/graphql \
28+
-H 'Content-Type: application/json' \
29+
-d '{
30+
"query": "{ markets(request: { chainIds: [<CHAIN_ID>] }) { reserves { underlyingToken { symbol decimals } supplyInfo { apy { formatted } } borrowInfo { apy { formatted } availableLiquidity { amount { value } usd } borrowCapReached } isFrozen isPaused } } }"
31+
}'
32+
```
33+
34+
## Present results
35+
36+
Filter out reserves where `isFrozen` or `isPaused` is `true`. For each active reserve, show:
37+
38+
- Token symbol and decimals (`underlyingToken.symbol`, `underlyingToken.decimals`)
39+
- Supply APY (`supplyInfo.apy.formatted`)
40+
- Borrow APY (`borrowInfo.apy.formatted`)
41+
- Available liquidity (`borrowInfo.availableLiquidity.amount.value`, `borrowInfo.availableLiquidity.usd`)
42+
- Borrow cap reached (`borrowInfo.borrowCapReached`)
43+
44+
The `apy.formatted` field returns a percentage directly (e.g., `"2.12"` means 2.12%). No conversion is needed.
45+
46+
If `borrowCapReached` is `true`, tell the user that borrowing isn't available for that asset.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Aave V3 positions workflow
2+
3+
Use this workflow to check Aave V3 positions, health factor, interest rates, or reserve data.
4+
5+
## Flow
6+
7+
1. Get wallet address and chain.
8+
2. Query supply and borrow positions via GraphQL.
9+
3. Present summary.
10+
11+
## Resolve chain
12+
13+
Get the wallet address:
14+
15+
```bash
16+
mm wallet address
17+
```
18+
19+
If the user doesn't specify a chain, ask. Aave V3 is deployed on these chains:
20+
21+
| Chain | Chain ID | Pool address |
22+
| --- | --- | --- |
23+
| Ethereum | 1 | `0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2` |
24+
| Polygon | 137 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` |
25+
| Arbitrum | 42161 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` |
26+
| Optimism | 10 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` |
27+
| Avalanche | 43114 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` |
28+
| Base | 8453 | `0x794a61358D6845594F94dc1DB02A252b5b4814aD` |
29+
30+
## Query positions
31+
32+
Query supply and borrow positions in a single request:
33+
34+
```bash
35+
curl -s -X POST https://api.v3.aave.com/graphql \
36+
-H 'Content-Type: application/json' \
37+
-d '{
38+
"query": "{ userSupplies(request: { markets: [{ address: \"<POOL_ADDRESS>\", chainId: <CHAIN_ID> }], user: \"<WALLET_ADDRESS>\" }) { currency { symbol decimals } balance { amount { value } usd } apy { formatted } isCollateral } userBorrows(request: { markets: [{ address: \"<POOL_ADDRESS>\", chainId: <CHAIN_ID> }], user: \"<WALLET_ADDRESS>\" }) { currency { symbol decimals } debt { amount { value } usd } apy { formatted } } }"
39+
}'
40+
```
41+
42+
The response contains both `userSupplies` and `userBorrows` arrays.
43+
44+
## Health factor preview
45+
46+
Preview the health factor impact of a planned operation:
47+
48+
```bash
49+
curl -s -X POST https://api.v3.aave.com/graphql \
50+
-H 'Content-Type: application/json' \
51+
-d '{
52+
"query": "{ healthFactorPreview(request: { action: { <OPERATION>: { market: \"<POOL_ADDRESS>\", sender: \"<WALLET_ADDRESS>\", chainId: <CHAIN_ID>, amount: { erc20: { currency: \"<ASSET_ADDRESS>\", value: \"<AMOUNT>\" } } } } }) { before after } }"
53+
}'
54+
```
55+
56+
Replace `<OPERATION>` with `supply`, `borrow`, `withdraw`, or `repay`. All action types require `market`, `sender`, and `chainId`.
57+
58+
## Present summary
59+
60+
Format the data into three sections:
61+
62+
Supplied assets:
63+
- Symbol, balance (`balance.amount.value`), USD value (`balance.usd`), supply APY (`apy.formatted`), used as collateral (`isCollateral`)
64+
65+
Borrowed assets:
66+
- Symbol, debt amount (`debt.amount.value`), USD value (`debt.usd`), borrow APY (`apy.formatted`)
67+
68+
Account summary:
69+
- Total collateral value, total debt value, available borrows, health factor
70+
- Health factor guidance: above 2.0 is safe, 1.5–2.0 is moderate, 1.0–1.5 is risky and approaching liquidation, below 1.0 is liquidatable
71+
72+
The `apy.formatted` field returns a percentage directly (e.g., `"2.12"` means 2.12%). No conversion is needed.

0 commit comments

Comments
 (0)