Aave V3 User Positions
Monitor user positions and account health across Aave markets.
User Positions
Track user supplied and borrowed assets across Aave markets.
Use the use and use hooks in React, the user and user actions in TypeScript, or the user and user queries in GraphQL to fetch user supplied and borrowed assets across markets.
In React, both hooks support a loading state and React Suspense.
const { data, loading, error } = useUserSupplies({
markets: MarketInput[],
user: EvmAddress,
});
const { data, loading, error } = useUserBorrows({
markets: MarketInput[],
user: EvmAddress,
});
const { data } = useUserSupplies({
markets: MarketInput[],
user: EvmAddress,
suspense: true,
});
const { data } = useUserBorrows({
markets: MarketInput[],
user: EvmAddress,
suspense: true,
});
Fetch user positions across one or more markets.
import { useUserSupplies, evmAddress } from "@aave/react";
import { markets } from "./markets";
// …
const user = evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234");
const { data, error, loading } = useUserSupplies({
markets,
user,
});
if (error) {
return <p>Error: {error.message}</p>;
}
if (loading) {
return <p>Loading positions…</p>;
}
// data: MarketUserReserveSupplyPosition[]
import { useUserBorrows, evmAddress } from "@aave/react";
import { markets } from "./markets";
// …
const user = evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234");
const { data, error, loading } = useUserBorrows({
markets,
user,
});
if (error) {
return <p>Error: {error.message}</p>;
}
if (loading) {
return <p>Loading positions…</p>;
}
// data: MarketUserReserveBorrowPosition[]
import { evmAddress, chainId } from "@aave/react";
export const markets = [
{
address: evmAddress("0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2"),
chainId: chainId(1),
},
];
import { userSupplies } from "@aave/client/actions";
import { evmAddress } from "@aave/client";
import { client } from "./client";
import { markets } from "./markets";
const user = evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234");
const result = await userSupplies(client, {
markets,
user,
});
if (result.isErr()) {
console.error("Supplies error:", result.error);
} else {
// result.value: MarketUserReserveSupplyPosition[]
console.log(result.value);
}
import { userBorrows } from "@aave/client/actions";
import { evmAddress } from "@aave/client";
import { client } from "./client";
import { markets } from "./markets";
const user = evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234");
const result = await userBorrows(client, {
markets,
user,
});
if (result.isErr()) {
console.error("Borrows error:", result.error);
} else {
// result.value: MarketUserReserveBorrowPosition[]
console.log(result.value);
}
import { evmAddress, chainId } from "@aave/client";
export const markets = [
{
address: evmAddress("0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2"),
chainId: chainId(1),
},
];
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
query {
userSupplies(
request: {
markets: [
{ address: "0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2", chainId: 1 }
]
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
}
) {
market {
name
chain {
chainId
}
}
currency {
symbol
name
}
balance {
amount {
value
}
usd
}
apy {
raw
decimals
value
formatted
}
isCollateral
canBeCollateral
}
}
query {
userBorrows(
request: {
markets: [
{ address: "0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2", chainId: 1 }
]
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
}
) {
market {
name
chain {
chainId
}
}
currency {
symbol
name
}
debt {
amount {
value
}
usd
}
apy {
raw
decimals
value
formatted
}
}
}
{
"data": {
"userSupplies": [
{
"market": {
"name": "Aave V3 Ethereum",
"chain": {
"chainId": 1
}
},
"currency": {
"symbol": "USDC",
"name": "USD Coin"
},
"balance": {
"amount": {
"value": "1000.0"
},
"usd": "1000.0"
},
"apy": {
"raw": "45000000000000000000000000",
"decimals": 27,
"value": "0.045",
"formatted": "4.5"
},
"isCollateral": true,
"canBeCollateral": true
}
]
}
}
{
"data": {
"userBorrows": [
{
"market": {
"name": "Aave V3 Ethereum",
"chain": {
"chainId": 1
}
},
"currency": {
"symbol": "WETH",
"name": "Wrapped Ether"
},
"debt": {
"amount": {
"value": "0.5"
},
"usd": "1250.0"
},
"apy": {
"raw": "28000000000000000000000000",
"decimals": 27,
"value": "0.028",
"formatted": "2.8"
}
}
]
}
}
Account Health
Monitor user account health and risk metrics across Aave positions.
The health factor is null unless the user has at least one active borrow.
Use the use hook in React, the user action in TypeScript, or the user query in GraphQL to fetch user account health and market state.
In React, the use hook supports both a loading state and React Suspense.
const { data, loading, error } = useUserMarketState({
market: EvmAddress,
user: EvmAddress,
chainId: ChainId,
});
const { data } = useUserMarketState({
market: EvmAddress,
user: EvmAddress,
chainId: ChainId,
suspense: true,
});
Monitor account health for a specific market.
import { useUserMarketState, evmAddress, chainId } from "@aave/react";
// …
const { data, loading, error } = useUserMarketState({
market: evmAddress("0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2"),
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
chainId: chainId(1),
});
if (loading) {
return <p>Loading account health…</p>;
}
if (error) {
return <p>Error: {error.message}</p>;
}
return (
<div>
<p>Health Factor: {data.healthFactor ?? "N/A"}</p>
<p>Net Worth: {data.netWorth}</p>
<p>eMode Enabled: {data.eModeEnabled ? "Yes" : "No"}</p>
</div>
);
import { evmAddress, chainId } from "@aave/client";
import { userMarketState } from "@aave/client/actions";
import { client } from "./client";
const result = await userMarketState(client, {
market: evmAddress("0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2"),
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
chainId: chainId(1),
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: MarketUserState
console.log("Health Factor:", result.value.healthFactor);
console.log("Net Worth:", result.value.netWorth);
console.log("eMode Enabled:", result.value.eModeEnabled);
}
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
query {
userMarketState(
request: {
market: "0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2"
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
chainId: 1
}
) {
netWorth
netAPY {
raw
decimals
value
formatted
}
healthFactor
eModeEnabled
totalCollateralBase
totalDebtBase
availableBorrowsBase
currentLiquidationThreshold {
raw
decimals
value
formatted
}
ltv {
raw
decimals
value
formatted
}
isInIsolationMode # deprecated in Aave V3.7
}
}
{
"data": {
"userMarketState": {
"netWorth": "5000.0",
"netAPY": {
"raw": "25000000000000000000000000",
"decimals": 27,
"value": "0.025",
"formatted": "2.5"
},
"healthFactor": "2.55",
"eModeEnabled": false,
"totalCollateralBase": "6000.0",
"totalDebtBase": "2000.0",
"availableBorrowsBase": "2500.0",
"currentLiquidationThreshold": {
"raw": "850000000000000000000000000",
"decimals": 27,
"value": "0.85",
"formatted": "85.0"
},
"ltv": {
"raw": "750000000000000000000000000",
"decimals": 27,
"value": "0.75",
"formatted": "75.0"
},
"isInIsolationMode": false
}
}
}