@moonwell-fi/moonwell-sdk 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/_cjs/actions/axiosWithRetry.js +10 -11
- package/_cjs/actions/axiosWithRetry.js.map +1 -1
- package/_cjs/actions/core/markets/common.js +30 -35
- package/_cjs/actions/core/markets/common.js.map +1 -1
- package/_cjs/actions/core/markets/getMarkets.js +7 -3
- package/_cjs/actions/core/markets/getMarkets.js.map +1 -1
- package/_cjs/actions/core/user-positions/common.js +56 -60
- package/_cjs/actions/core/user-positions/common.js.map +1 -1
- package/_cjs/actions/core/user-positions/getUserPositions.js +9 -6
- package/_cjs/actions/core/user-positions/getUserPositions.js.map +1 -1
- package/_cjs/actions/governance/proposals/common.js +0 -5
- package/_cjs/actions/governance/proposals/common.js.map +1 -1
- package/_cjs/actions/index.js +3 -1
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/morpho/markets/common.js +128 -26
- package/_cjs/actions/morpho/markets/common.js.map +1 -1
- package/_cjs/actions/morpho/markets/getMorphoMarket.js +1 -0
- package/_cjs/actions/morpho/markets/getMorphoMarket.js.map +1 -1
- package/_cjs/actions/morpho/markets/getMorphoMarkets.js +1 -0
- package/_cjs/actions/morpho/markets/getMorphoMarkets.js.map +1 -1
- package/_cjs/actions/morpho/markets/getMorphoMarketsSharedLiquidity.js +46 -0
- package/_cjs/actions/morpho/markets/getMorphoMarketsSharedLiquidity.js.map +1 -0
- package/_cjs/actions/morpho/user-positions/common.js +26 -24
- package/_cjs/actions/morpho/user-positions/common.js.map +1 -1
- package/_cjs/actions/morpho/user-positions/getMorphoMarketUserPositions.js +7 -8
- package/_cjs/actions/morpho/user-positions/getMorphoMarketUserPositions.js.map +1 -1
- package/_cjs/actions/morpho/user-positions/getMorphoVaultUserPositions.js +7 -8
- package/_cjs/actions/morpho/user-positions/getMorphoVaultUserPositions.js.map +1 -1
- package/_cjs/actions/retry.js +43 -13
- package/_cjs/actions/retry.js.map +1 -1
- package/_cjs/client/createActions.js +2 -0
- package/_cjs/client/createActions.js.map +1 -1
- package/_cjs/common/error.js +37 -1
- package/_cjs/common/error.js.map +1 -1
- package/_cjs/common/index.js +2 -1
- package/_cjs/common/index.js.map +1 -1
- package/_cjs/common/readAcrossEnvironments.js +17 -0
- package/_cjs/common/readAcrossEnvironments.js.map +1 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_esm/actions/axiosWithRetry.js +11 -13
- package/_esm/actions/axiosWithRetry.js.map +1 -1
- package/_esm/actions/core/markets/common.js +34 -35
- package/_esm/actions/core/markets/common.js.map +1 -1
- package/_esm/actions/core/markets/getMarkets.js +7 -3
- package/_esm/actions/core/markets/getMarkets.js.map +1 -1
- package/_esm/actions/core/user-positions/common.js +65 -63
- package/_esm/actions/core/user-positions/common.js.map +1 -1
- package/_esm/actions/core/user-positions/getUserPositions.js +14 -6
- package/_esm/actions/core/user-positions/getUserPositions.js.map +1 -1
- package/_esm/actions/governance/proposals/common.js +0 -2
- package/_esm/actions/governance/proposals/common.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/morpho/markets/common.js +136 -27
- package/_esm/actions/morpho/markets/common.js.map +1 -1
- package/_esm/actions/morpho/markets/getMorphoMarket.js +1 -0
- package/_esm/actions/morpho/markets/getMorphoMarket.js.map +1 -1
- package/_esm/actions/morpho/markets/getMorphoMarkets.js +1 -0
- package/_esm/actions/morpho/markets/getMorphoMarkets.js.map +1 -1
- package/_esm/actions/morpho/markets/getMorphoMarketsSharedLiquidity.js +48 -0
- package/_esm/actions/morpho/markets/getMorphoMarketsSharedLiquidity.js.map +1 -0
- package/_esm/actions/morpho/user-positions/common.js +31 -24
- package/_esm/actions/morpho/user-positions/common.js.map +1 -1
- package/_esm/actions/morpho/user-positions/getMorphoMarketUserPositions.js +12 -8
- package/_esm/actions/morpho/user-positions/getMorphoMarketUserPositions.js.map +1 -1
- package/_esm/actions/morpho/user-positions/getMorphoVaultUserPositions.js +12 -8
- package/_esm/actions/morpho/user-positions/getMorphoVaultUserPositions.js.map +1 -1
- package/_esm/actions/retry.js +45 -15
- package/_esm/actions/retry.js.map +1 -1
- package/_esm/client/createActions.js +2 -0
- package/_esm/client/createActions.js.map +1 -1
- package/_esm/common/error.js +49 -0
- package/_esm/common/error.js.map +1 -1
- package/_esm/common/index.js +1 -1
- package/_esm/common/index.js.map +1 -1
- package/_esm/common/readAcrossEnvironments.js +30 -0
- package/_esm/common/readAcrossEnvironments.js.map +1 -0
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_types/actions/axiosWithRetry.d.ts +1 -0
- package/_types/actions/axiosWithRetry.d.ts.map +1 -1
- package/_types/actions/core/markets/common.d.ts.map +1 -1
- package/_types/actions/core/markets/getMarkets.d.ts.map +1 -1
- package/_types/actions/core/user-positions/common.d.ts.map +1 -1
- package/_types/actions/core/user-positions/getUserPositions.d.ts +5 -0
- package/_types/actions/core/user-positions/getUserPositions.d.ts.map +1 -1
- package/_types/actions/governance/proposals/common.d.ts.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/morpho/markets/common.d.ts +7 -10
- package/_types/actions/morpho/markets/common.d.ts.map +1 -1
- package/_types/actions/morpho/markets/getMorphoMarket.d.ts +2 -0
- package/_types/actions/morpho/markets/getMorphoMarket.d.ts.map +1 -1
- package/_types/actions/morpho/markets/getMorphoMarkets.d.ts +2 -0
- package/_types/actions/morpho/markets/getMorphoMarkets.d.ts.map +1 -1
- package/_types/actions/morpho/markets/getMorphoMarketsSharedLiquidity.d.ts +17 -0
- package/_types/actions/morpho/markets/getMorphoMarketsSharedLiquidity.d.ts.map +1 -0
- package/_types/actions/morpho/user-positions/common.d.ts.map +1 -1
- package/_types/actions/morpho/user-positions/getMorphoMarketUserPositions.d.ts +5 -0
- package/_types/actions/morpho/user-positions/getMorphoMarketUserPositions.d.ts.map +1 -1
- package/_types/actions/morpho/user-positions/getMorphoVaultUserPositions.d.ts +5 -0
- package/_types/actions/morpho/user-positions/getMorphoVaultUserPositions.d.ts.map +1 -1
- package/_types/actions/retry.d.ts +5 -4
- package/_types/actions/retry.d.ts.map +1 -1
- package/_types/client/createActions.d.ts +2 -0
- package/_types/client/createActions.d.ts.map +1 -1
- package/_types/common/error.d.ts +31 -0
- package/_types/common/error.d.ts.map +1 -1
- package/_types/common/index.d.ts +2 -2
- package/_types/common/index.d.ts.map +1 -1
- package/_types/common/readAcrossEnvironments.d.ts +23 -0
- package/_types/common/readAcrossEnvironments.d.ts.map +1 -0
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +3 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/types/morphoMarket.d.ts +9 -0
- package/_types/types/morphoMarket.d.ts.map +1 -1
- package/actions/axiosWithRetry.ts +19 -13
- package/actions/core/markets/common.ts +44 -43
- package/actions/core/markets/getMarkets.ts +9 -5
- package/actions/core/user-positions/common.ts +107 -111
- package/actions/core/user-positions/getUserPositions.ts +11 -10
- package/actions/governance/proposals/common.ts +0 -3
- package/actions/index.ts +5 -0
- package/actions/morpho/markets/common.ts +289 -125
- package/actions/morpho/markets/getMorphoMarket.ts +3 -0
- package/actions/morpho/markets/getMorphoMarkets.ts +3 -0
- package/actions/morpho/markets/getMorphoMarketsSharedLiquidity.ts +93 -0
- package/actions/morpho/user-positions/common.ts +48 -42
- package/actions/morpho/user-positions/getMorphoMarketUserPositions.ts +14 -15
- package/actions/morpho/user-positions/getMorphoVaultUserPositions.ts +14 -15
- package/actions/retry.ts +53 -18
- package/client/createActions.ts +13 -0
- package/common/error.ts +45 -0
- package/common/index.ts +2 -2
- package/common/readAcrossEnvironments.ts +45 -0
- package/errors/version.ts +1 -1
- package/index.ts +3 -0
- package/package.json +1 -1
- package/types/morphoMarket.ts +10 -0
|
@@ -14,17 +14,22 @@ import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
|
|
|
14
14
|
|
|
15
15
|
import { retry } from "./retry.js";
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
//
|
|
17
|
+
// Request-local defaults: importing the SDK must not change the host app's axios
|
|
18
|
+
// defaults. Callers with a different budget can override this timeout explicitly.
|
|
19
|
+
export const DEFAULT_API_TIMEOUT_MS = 5_000;
|
|
19
20
|
|
|
20
21
|
export function getWithRetry<T = unknown>(
|
|
21
22
|
url: string,
|
|
22
23
|
config?: AxiosRequestConfig,
|
|
23
24
|
): Promise<AxiosResponse<T>> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
return retry(
|
|
26
|
+
() =>
|
|
27
|
+
axios.get<T>(url, {
|
|
28
|
+
...config,
|
|
29
|
+
timeout: config?.timeout ?? DEFAULT_API_TIMEOUT_MS,
|
|
30
|
+
}),
|
|
31
|
+
{ signal: config?.signal },
|
|
32
|
+
);
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
export function postWithRetry<T = unknown, D = unknown>(
|
|
@@ -32,11 +37,12 @@ export function postWithRetry<T = unknown, D = unknown>(
|
|
|
32
37
|
data?: D,
|
|
33
38
|
config?: AxiosRequestConfig<D>,
|
|
34
39
|
): Promise<AxiosResponse<T>> {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
return retry(
|
|
41
|
+
() =>
|
|
42
|
+
axios.post<T, AxiosResponse<T>, D>(url, data, {
|
|
43
|
+
...config,
|
|
44
|
+
timeout: config?.timeout ?? DEFAULT_API_TIMEOUT_MS,
|
|
45
|
+
}),
|
|
46
|
+
{ signal: config?.signal },
|
|
47
|
+
);
|
|
42
48
|
}
|
|
@@ -876,54 +876,55 @@ async function fetchMarketsFromLunar(
|
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
const fetchFromGenericCacheApi = async <T>(uri: string): Promise<T> => {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
879
|
+
// AbortSignal.timeout is not available in every browser supported by SDK
|
|
880
|
+
// consumers. Keep the timeout local and release it after reading the body.
|
|
881
|
+
const controller = new AbortController();
|
|
882
|
+
const timer = setTimeout(() => controller.abort(), 5_000);
|
|
883
|
+
try {
|
|
884
|
+
const response = await fetch(
|
|
885
|
+
"https://generic-api-cache.moonwell.workers.dev/",
|
|
886
|
+
{
|
|
887
|
+
method: "POST",
|
|
888
|
+
body: `{"uri":"${uri}","cacheDuration":"300"}`,
|
|
889
|
+
signal: controller.signal,
|
|
890
|
+
headers: {
|
|
891
|
+
...MOONWELL_FETCH_JSON_HEADERS,
|
|
892
|
+
"Content-Type": "text/plain",
|
|
893
|
+
},
|
|
887
894
|
},
|
|
888
|
-
|
|
889
|
-
);
|
|
895
|
+
);
|
|
890
896
|
|
|
891
|
-
|
|
897
|
+
if (!response.ok)
|
|
898
|
+
throw new Error(`Staking APR request failed: ${response.status}`);
|
|
899
|
+
return await response.json();
|
|
900
|
+
} finally {
|
|
901
|
+
clearTimeout(timer);
|
|
902
|
+
}
|
|
892
903
|
};
|
|
893
904
|
|
|
894
|
-
export const fetchLiquidStakingRewards = async ()
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
905
|
+
export const fetchLiquidStakingRewards = async (): Promise<{
|
|
906
|
+
cbETH: number;
|
|
907
|
+
rETH: number;
|
|
908
|
+
wstETH: number;
|
|
909
|
+
}> => {
|
|
910
|
+
// Each provider can succeed independently, and each has a bounded request.
|
|
911
|
+
// Preserve the existing zero fallback for callers of this optional enrichment.
|
|
912
|
+
const [cbETH, rETH, wstETH] = await Promise.all([
|
|
913
|
+
fetchFromGenericCacheApi<{ apy: string }>(
|
|
903
914
|
"https://api.exchange.coinbase.com/wrapped-assets/CBETH",
|
|
904
|
-
)
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
try {
|
|
911
|
-
const rETH = await fetchFromGenericCacheApi<{ rethAPR: string }>(
|
|
915
|
+
)
|
|
916
|
+
.then((result) => Number(result.apy) * 100)
|
|
917
|
+
.catch(() => 0),
|
|
918
|
+
fetchFromGenericCacheApi<{ rethAPR: string }>(
|
|
912
919
|
"https://rocketpool.net/api/mainnet/payload",
|
|
913
|
-
)
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
try {
|
|
920
|
-
const stETH = await fetchFromGenericCacheApi<{ data: { apr: number } }>(
|
|
920
|
+
)
|
|
921
|
+
.then((result) => Number(result.rethAPR))
|
|
922
|
+
.catch(() => 0),
|
|
923
|
+
fetchFromGenericCacheApi<{ data: { apr: number } }>(
|
|
921
924
|
"https://eth-api.lido.fi/v1/protocol/steth/apr/last",
|
|
922
|
-
)
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
return result;
|
|
925
|
+
)
|
|
926
|
+
.then((result) => result.data.apr)
|
|
927
|
+
.catch(() => 0),
|
|
928
|
+
]);
|
|
929
|
+
return { cbETH, rETH, wstETH };
|
|
929
930
|
};
|
|
@@ -25,9 +25,14 @@ export async function getMarkets<
|
|
|
25
25
|
const environments = getEnvironmentsFromArgs(client, args);
|
|
26
26
|
const logId = logger.start("getMarkets", "Starting to get markets...");
|
|
27
27
|
|
|
28
|
-
const settlements = await Promise.
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const [settlements, liquidStakingRewards] = await Promise.all([
|
|
29
|
+
Promise.allSettled(
|
|
30
|
+
environments.map((environment) => getMarketsData(environment)),
|
|
31
|
+
),
|
|
32
|
+
args?.includeLiquidStakingRewards === true
|
|
33
|
+
? fetchLiquidStakingRewards()
|
|
34
|
+
: undefined,
|
|
35
|
+
]);
|
|
31
36
|
|
|
32
37
|
const result = settlements
|
|
33
38
|
.filter(
|
|
@@ -35,8 +40,7 @@ export async function getMarkets<
|
|
|
35
40
|
)
|
|
36
41
|
.map((s) => s.value);
|
|
37
42
|
|
|
38
|
-
if (
|
|
39
|
-
const liquidStakingRewards = await fetchLiquidStakingRewards();
|
|
43
|
+
if (liquidStakingRewards) {
|
|
40
44
|
for (const item of result.flat()) {
|
|
41
45
|
if (item.underlyingToken.symbol.toLowerCase() === "cbeth") {
|
|
42
46
|
item.rewards.push({
|
|
@@ -15,117 +15,113 @@ export const getUserPositionData = async (params: {
|
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
])
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
// Only getAllMarketsInfo is settled, because it has the mToken fallback
|
|
19
|
+
// below. The three user reads have no fallback: Promise.all lets their first
|
|
20
|
+
// rejection propagate instead of being treated as an empty list, which would
|
|
21
|
+
// misreport the user as having no position (MOO-885).
|
|
22
|
+
const [[allMarketsResult], balances, borrows, memberships] =
|
|
23
|
+
await Promise.all([
|
|
24
|
+
Promise.allSettled([viewsContract.read.getAllMarketsInfo()]),
|
|
25
|
+
viewsContract.read.getUserBalances([params.account]),
|
|
26
|
+
viewsContract.read.getUserBorrowsBalances([params.account]),
|
|
27
|
+
viewsContract.read.getUserMarketsMemberships([params.account]),
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
// If getAllMarketsInfo failed (e.g. broken on-chain oracle), fall back to
|
|
31
|
+
// per-mToken exchange rate calls. The user balance/borrow/membership calls
|
|
32
|
+
// don't touch the oracle so they can still succeed. The fallback reports
|
|
33
|
+
// every USD value as 0, so the degraded read is surfaced through onError
|
|
34
|
+
// instead of passing as a healthy result.
|
|
35
|
+
if (allMarketsResult.status === "rejected") {
|
|
36
|
+
params.environment.onError?.(allMarketsResult.reason, {
|
|
37
|
+
source: "user-positions-oracle-fallback",
|
|
38
|
+
chainId: params.environment.chainId,
|
|
39
|
+
});
|
|
40
|
+
return getUserPositionsFromMTokenFallback(
|
|
41
|
+
params,
|
|
42
|
+
balances,
|
|
43
|
+
borrows,
|
|
44
|
+
memberships,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
const allMarkets = allMarketsResult.value;
|
|
49
|
+
|
|
50
|
+
const markets = allMarkets
|
|
51
|
+
?.map((marketInfo) => {
|
|
52
|
+
const market = findMarketByAddress(params.environment, marketInfo.market);
|
|
53
|
+
if (market) {
|
|
54
|
+
const { marketToken, underlyingToken } = market;
|
|
55
|
+
|
|
56
|
+
const underlyingPrice = new Amount(
|
|
57
|
+
marketInfo.underlyingPrice,
|
|
58
|
+
36 - underlyingToken.decimals,
|
|
59
|
+
).value;
|
|
60
|
+
const collateralFactor = new Amount(marketInfo.collateralFactor, 18)
|
|
61
|
+
.value;
|
|
62
|
+
const exchangeRate = new Amount(
|
|
63
|
+
marketInfo.exchangeRate,
|
|
64
|
+
10 + underlyingToken.decimals,
|
|
65
|
+
).value;
|
|
66
|
+
|
|
67
|
+
const marketCollateralEnabled =
|
|
68
|
+
memberships?.find((r) => r.token === marketInfo.market)
|
|
69
|
+
?.membership === true;
|
|
70
|
+
const marketBorrowedRaw =
|
|
71
|
+
borrows?.find((r) => r.token === marketInfo.market)?.amount || 0n;
|
|
72
|
+
const marketSuppliedRaw =
|
|
73
|
+
balances?.find((r) => r.token === marketInfo.market)?.amount || 0n;
|
|
74
|
+
|
|
75
|
+
const borrowed = new Amount(
|
|
76
|
+
marketBorrowedRaw,
|
|
77
|
+
market.underlyingToken.decimals,
|
|
78
|
+
);
|
|
79
|
+
const borrowedUsd = borrowed.value * underlyingPrice;
|
|
47
80
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
params.environment,
|
|
52
|
-
marketInfo.market,
|
|
81
|
+
const marketSupplied = new Amount(
|
|
82
|
+
marketSuppliedRaw,
|
|
83
|
+
marketToken.decimals,
|
|
53
84
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
? new Amount(
|
|
95
|
-
supplied.value * collateralFactor,
|
|
96
|
-
underlyingToken.decimals,
|
|
97
|
-
)
|
|
98
|
-
: new Amount(0n, underlyingToken.decimals);
|
|
99
|
-
|
|
100
|
-
const collateralUsd = collateral.value * underlyingPrice;
|
|
101
|
-
|
|
102
|
-
const result: UserPosition = {
|
|
103
|
-
chainId: params.environment.chainId,
|
|
104
|
-
account: params.account,
|
|
105
|
-
market: market.marketToken,
|
|
106
|
-
collateralEnabled: marketCollateralEnabled,
|
|
107
|
-
borrowed,
|
|
108
|
-
borrowedUsd,
|
|
109
|
-
collateral,
|
|
110
|
-
collateralUsd,
|
|
111
|
-
supplied,
|
|
112
|
-
suppliedUsd,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
return result;
|
|
116
|
-
} else {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
.filter((r) => r !== undefined)
|
|
121
|
-
.filter((r) =>
|
|
122
|
-
params.markets ? params.markets.includes(r!.market.address) : true,
|
|
123
|
-
) as UserPosition[];
|
|
124
|
-
|
|
125
|
-
return markets;
|
|
126
|
-
} catch {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
85
|
+
|
|
86
|
+
const supplied = new Amount(
|
|
87
|
+
marketSupplied.value * exchangeRate,
|
|
88
|
+
underlyingToken.decimals,
|
|
89
|
+
);
|
|
90
|
+
const suppliedUsd = supplied.value * underlyingPrice;
|
|
91
|
+
|
|
92
|
+
const collateral = marketCollateralEnabled
|
|
93
|
+
? new Amount(
|
|
94
|
+
supplied.value * collateralFactor,
|
|
95
|
+
underlyingToken.decimals,
|
|
96
|
+
)
|
|
97
|
+
: new Amount(0n, underlyingToken.decimals);
|
|
98
|
+
|
|
99
|
+
const collateralUsd = collateral.value * underlyingPrice;
|
|
100
|
+
|
|
101
|
+
const result: UserPosition = {
|
|
102
|
+
chainId: params.environment.chainId,
|
|
103
|
+
account: params.account,
|
|
104
|
+
market: market.marketToken,
|
|
105
|
+
collateralEnabled: marketCollateralEnabled,
|
|
106
|
+
borrowed,
|
|
107
|
+
borrowedUsd,
|
|
108
|
+
collateral,
|
|
109
|
+
collateralUsd,
|
|
110
|
+
supplied,
|
|
111
|
+
suppliedUsd,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
} else {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
.filter((r) => r !== undefined)
|
|
120
|
+
.filter((r) =>
|
|
121
|
+
params.markets ? params.markets.includes(r!.market.address) : true,
|
|
122
|
+
) as UserPosition[];
|
|
123
|
+
|
|
124
|
+
return markets;
|
|
129
125
|
};
|
|
130
126
|
|
|
131
127
|
/**
|
|
@@ -141,9 +137,9 @@ async function getUserPositionsFromMTokenFallback(
|
|
|
141
137
|
account: Address;
|
|
142
138
|
markets?: string[] | undefined;
|
|
143
139
|
},
|
|
144
|
-
balances: { amount: bigint; token: `0x${string}` }[],
|
|
145
|
-
borrows: { amount: bigint; token: `0x${string}` }[],
|
|
146
|
-
memberships: { membership: boolean; token: `0x${string}` }[],
|
|
140
|
+
balances: readonly { amount: bigint; token: `0x${string}` }[],
|
|
141
|
+
borrows: readonly { amount: bigint; token: `0x${string}` }[],
|
|
142
|
+
memberships: readonly { membership: boolean; token: `0x${string}` }[],
|
|
147
143
|
): Promise<UserPosition[]> {
|
|
148
144
|
const positions: UserPosition[] = [];
|
|
149
145
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Address, Chain } from "viem";
|
|
2
2
|
import type { MoonwellClient } from "../../../client/createMoonwellClient.js";
|
|
3
3
|
import { getEnvironmentsFromArgs } from "../../../common/index.js";
|
|
4
|
+
import { readAcrossEnvironments } from "../../../common/readAcrossEnvironments.js";
|
|
4
5
|
import type { OptionalNetworkParameterType } from "../../../common/types.js";
|
|
5
6
|
import type { UserPosition } from "../../../types/userPosition.js";
|
|
6
7
|
import { getUserPositionData } from "./common.js";
|
|
@@ -15,6 +16,11 @@ export type GetUserPositionsParameters<
|
|
|
15
16
|
|
|
16
17
|
export type GetUserPositionsReturnType = Promise<UserPosition[]>;
|
|
17
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Rejects with a `ChainReadError` when the read fails on any requested chain,
|
|
21
|
+
* so a failed RPC never looks like an empty position list. The error lists the
|
|
22
|
+
* failed chains and carries the positions from the chains that succeeded.
|
|
23
|
+
*/
|
|
18
24
|
export async function getUserPositions<
|
|
19
25
|
environments,
|
|
20
26
|
Network extends Chain | undefined,
|
|
@@ -26,18 +32,13 @@ export async function getUserPositions<
|
|
|
26
32
|
|
|
27
33
|
const environments = getEnvironmentsFromArgs(client, args);
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
environments
|
|
35
|
+
return readAcrossEnvironments({
|
|
36
|
+
environments,
|
|
37
|
+
source: "getUserPositions",
|
|
38
|
+
read: (environment) =>
|
|
31
39
|
getUserPositionData({
|
|
32
40
|
environment,
|
|
33
41
|
account: userAddress,
|
|
34
42
|
}),
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const result = settled.flatMap((s) =>
|
|
39
|
-
s.status === "fulfilled" ? s.value : [],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
+
});
|
|
43
44
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { mainnet } from "viem/chains";
|
|
3
2
|
import { Amount } from "../../../common/index.js";
|
|
4
3
|
import type { Environment } from "../../../environments/index.js";
|
|
@@ -23,8 +22,6 @@ const MULTICHAIN_WORMHOLE_BRIDGES: ReadonlySet<string> = new Set([
|
|
|
23
22
|
"0x98f3c9e6e3face36baad05fe09d375ef1464288b", // Ethereum
|
|
24
23
|
]);
|
|
25
24
|
|
|
26
|
-
axios.defaults.timeout = 5_000;
|
|
27
|
-
|
|
28
25
|
/**
|
|
29
26
|
* Extract proposal subtitle from description
|
|
30
27
|
*/
|
package/actions/index.ts
CHANGED
|
@@ -116,6 +116,11 @@ export {
|
|
|
116
116
|
type GetMorphoMarketsParameters,
|
|
117
117
|
type GetMorphoMarketsReturnType,
|
|
118
118
|
} from "./morpho/markets/getMorphoMarkets.js";
|
|
119
|
+
export {
|
|
120
|
+
getMorphoMarketsSharedLiquidity,
|
|
121
|
+
type GetMorphoMarketsSharedLiquidityParameters,
|
|
122
|
+
type GetMorphoMarketsSharedLiquidityReturnType,
|
|
123
|
+
} from "./morpho/markets/getMorphoMarketsSharedLiquidity.js";
|
|
119
124
|
export {
|
|
120
125
|
getMarketSnapshots as getMorphoMarketSnapshots,
|
|
121
126
|
type GetMarketSnapshotsParameters as GetMorphoMarketSnapshotsParameters,
|