getUserPositions
Returns all user positions across Moonwell core and isolated markets.
Usage
import { moonwellClient } from './client'
const positions = await moonwellClient.getUserPositions({
userAddress: "0x0000000000000000000000000000000000000000",
});Returns
Example
UserPosition[]- Type:
UserPosition[]
Errors
The promise rejects with a ChainReadError when the read fails on any requested chain, so a failed RPC never looks like an empty position list. error.failures lists each failed chain as { chainId, reason } with the original error, error.data carries the positions from the chains that succeeded, and error.source is "getUserPositions". The failure is not additionally reported through the client's onError callback. Chains without the relevant deployment are skipped, and an account with no positions resolves normally.
If only the getAllMarketsInfo read fails, positions are computed from per-mToken reads with USD values of 0, and that failure is reported through onError with source: "user-positions-oracle-fallback".
Parameters
userAddress
- Type:
Address
The address of the user.
const positions = await moonwellClient.getUserPositions({
userAddress: "0x0000000000000000000000000000000000000000",
});chainId (optional)
- Type:
number
The chain ID to get the positions for.
const positions = await moonwellClient.getUserPositions({
userAddress: "0x0000000000000000000000000000000000000000",
chainId: 8453,
});network (optional)
- Type:
string
The network to filter the markets by.
import { base } from "@moonwell-fi/moonwell-sdk/environments";
const positions = await moonwellClient.getUserPositions<typeof base>({
userAddress: "0x0000000000000000000000000000000000000000",
network: "base"
})