@varla/sdk 2.18.0 → 2.20.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.
@@ -1 +1 @@
1
- {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/views/system.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAGnB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,kBAAkB,CAAC;IACnC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,eAAe,EAAE,qBAAqB,CAAC;IACvC,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,kBAAkB,GAAG;IAC7D,cAAc,EAAE,kBAAkB,CAAC;IACnC,eAAe,EAAE,mBAAmB,CAAC;CACtC,CAAC;AAEF;;;;;;GAMG;AAEH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE;IAC/C,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,GAAG,CAAC;CACb,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAW9B;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAAC,MAAM,EAAE;IACxD,IAAI,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,CAAC;IACjC,IAAI,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,CAAC;IACjC,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,E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,EAAE,CAAA;KAAE,CAAC;IACjC,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE;QAAE,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;CACpD,GAAG,OAAO,CAAC,2BAA2B,CAAC,CA4BvC"}
@@ -49,6 +49,7 @@ export async function readSystemDashboardSnapshot(params) {
49
49
  oracle,
50
50
  poolSharePrice: poolDashboard.sharePrice,
51
51
  poolHealthScore: poolDashboard.healthScore,
52
+ coreAddresses: coreDashboard.coreAddresses,
52
53
  };
53
54
  }
54
55
  //# sourceMappingURL=system.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","sourceRoot":"","sources":["../../src/views/system.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAGpE,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQ/C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAgBlG;;;;;;GAMG;AACH,mVAAmV;AACnV,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAIxC;IACC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC3F,gBAAgB,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACvC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACnC,kBAAkB,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACzC,oBAAoB,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3C,qBAAqB,CAAC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,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;YACtC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;QACF,iBAAiB,CAAC;YAChB,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;YACtC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;QACF,gBAAgB,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;KAC5C,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,aAAa,CAAC,QAAQ;QAC5B,QAAQ,EAAE,aAAa,CAAC,IAAI;QAC5B,cAAc,EAAE,aAAa,CAAC,UAAU;QACxC,OAAO,EAAE;YACP,YAAY,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK;YAC3C,QAAQ,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK;YACvC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK;SACpC;QACD,eAAe,EAAE,aAAa,CAAC,SAAS;QACxC,MAAM;QACN,cAAc,EAAE,aAAa,CAAC,UAAU;QACxC,eAAe,EAAE,aAAa,CAAC,WAAW;QAC1C,aAAa,EAAE,aAAa,CAAC,aAAa;KAC3C,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varla/sdk",
3
- "version": "2.18.0",
3
+ "version": "2.20.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -5,6 +5,14 @@ import type { Address, PublicClient } from "viem";
5
5
  import { abis } from "../generated.js";
6
6
  import type { SimulatedTx } from "./oracle.js";
7
7
 
8
+ type LiquidatorKind = "standard" | "merge" | "convert";
9
+
10
+ function getLiquidatorAbi(kind: LiquidatorKind | undefined) {
11
+ if (kind === "merge") return abis.VARLAMERGELIQUIDATOR_ABI;
12
+ if (kind === "convert") return abis.VARLACONVERTLIQUIDATOR_ABI;
13
+ return abis.VARLALIQUIDATOR_ABI;
14
+ }
15
+
8
16
  // ---------------------------------------------------------------------------
9
17
  // Liquidator (bot flows) write helpers
10
18
  // ---------------------------------------------------------------------------
@@ -74,3 +82,76 @@ export async function prepareLiquidatorResolveBadDebtWithReserve(params: {
74
82
  account: params.account,
75
83
  } as any)) as any;
76
84
  }
85
+
86
+ // ---------------------------------------------------------------------------
87
+ // Liquidator admin/config helpers (VarlaLiquidatorBase)
88
+ // ---------------------------------------------------------------------------
89
+
90
+ export async function prepareLiquidatorSetTreasury(params: {
91
+ publicClient: Pick<PublicClient, "simulateContract">;
92
+ liquidatorAddress: Address;
93
+ account: Address;
94
+ treasury: Address;
95
+ kind?: LiquidatorKind;
96
+ }): Promise<SimulatedTx> {
97
+ return (await params.publicClient.simulateContract({
98
+ address: params.liquidatorAddress,
99
+ abi: getLiquidatorAbi(params.kind),
100
+ functionName: "setTreasury",
101
+ args: [params.treasury],
102
+ account: params.account,
103
+ } as any)) as any;
104
+ }
105
+
106
+ export async function prepareLiquidatorSetStaking(params: {
107
+ publicClient: Pick<PublicClient, "simulateContract">;
108
+ liquidatorAddress: Address;
109
+ account: Address;
110
+ staking: Address;
111
+ kind?: LiquidatorKind;
112
+ }): Promise<SimulatedTx> {
113
+ return (await params.publicClient.simulateContract({
114
+ address: params.liquidatorAddress,
115
+ abi: getLiquidatorAbi(params.kind),
116
+ functionName: "setStaking",
117
+ args: [params.staking],
118
+ account: params.account,
119
+ } as any)) as any;
120
+ }
121
+
122
+ export async function prepareLiquidatorRescueErc20(params: {
123
+ publicClient: Pick<PublicClient, "simulateContract">;
124
+ liquidatorAddress: Address;
125
+ account: Address;
126
+ token: Address;
127
+ to: Address;
128
+ amount: bigint;
129
+ kind?: LiquidatorKind;
130
+ }): Promise<SimulatedTx> {
131
+ return (await params.publicClient.simulateContract({
132
+ address: params.liquidatorAddress,
133
+ abi: getLiquidatorAbi(params.kind),
134
+ functionName: "rescueERC20",
135
+ args: [params.token, params.to, params.amount],
136
+ account: params.account,
137
+ } as any)) as any;
138
+ }
139
+
140
+ export async function prepareLiquidatorRescueErc1155(params: {
141
+ publicClient: Pick<PublicClient, "simulateContract">;
142
+ liquidatorAddress: Address;
143
+ account: Address;
144
+ token: Address;
145
+ to: Address;
146
+ id: bigint;
147
+ amount: bigint;
148
+ kind?: LiquidatorKind;
149
+ }): Promise<SimulatedTx> {
150
+ return (await params.publicClient.simulateContract({
151
+ address: params.liquidatorAddress,
152
+ abi: getLiquidatorAbi(params.kind),
153
+ functionName: "rescueERC1155",
154
+ args: [params.token, params.to, params.id, params.amount],
155
+ account: params.account,
156
+ } as any)) as any;
157
+ }
@@ -83,6 +83,38 @@ export async function prepareOracleSetPositionEarlyClosureWindowOverride(params:
83
83
  } as any)) as any;
84
84
  }
85
85
 
86
+ export async function prepareOracleSetLowLiquidityConfig(params: {
87
+ publicClient: Pick<PublicClient, "simulateContract">;
88
+ oracleAddress: Address;
89
+ account: Address;
90
+ tier: number;
91
+ gracePeriod: bigint;
92
+ decayPeriod: bigint;
93
+ }): Promise<SimulatedTx> {
94
+ return (await params.publicClient.simulateContract({
95
+ address: params.oracleAddress,
96
+ abi: abis.VARLAORACLE_ABI,
97
+ functionName: "setLowLiquidityConfig",
98
+ args: [params.tier, params.gracePeriod, params.decayPeriod],
99
+ account: params.account,
100
+ } as any)) as any;
101
+ }
102
+
103
+ export async function prepareOracleSetLowLiquidityGraceBlocksLiquidation(params: {
104
+ publicClient: Pick<PublicClient, "simulateContract">;
105
+ oracleAddress: Address;
106
+ account: Address;
107
+ shouldBlock: boolean;
108
+ }): Promise<SimulatedTx> {
109
+ return (await params.publicClient.simulateContract({
110
+ address: params.oracleAddress,
111
+ abi: abis.VARLAORACLE_ABI,
112
+ functionName: "setLowLiquidityGraceBlocksLiquidation",
113
+ args: [params.shouldBlock],
114
+ account: params.account,
115
+ } as any)) as any;
116
+ }
117
+
86
118
  export async function prepareOracleClearPositionEarlyClosureWindowOverride(params: {
87
119
  publicClient: Pick<PublicClient, "simulateContract">;
88
120
  oracleAddress: Address;
@@ -563,8 +595,11 @@ export async function seedOracleFromJsonFiles(params: {
563
595
  }): Promise<SeedOracleFromJsonResult> {
564
596
  let readFileSync: ((path: string, enc: "utf8") => string) | undefined;
565
597
  try {
566
- // Node 18+/Bun supports `node:fs`.
567
- ({ readFileSync } = (await import("node:fs")) as any);
598
+ // Use Function(...) so browser bundlers don't statically analyze node:fs imports.
599
+ const importRuntime = Function("s", "return import(s)") as (
600
+ specifier: string,
601
+ ) => Promise<{ readFileSync?: (path: string, enc: "utf8") => string }>;
602
+ ({ readFileSync } = (await importRuntime(["node", "fs"].join(":"))) as any);
568
603
  } catch {
569
604
  throw new Error(
570
605
  "seedOracleFromJsonFiles() is Node-only. In browsers, load JSON via fetch and call seedOracleFromJson().",
package/src/views/core.ts CHANGED
@@ -904,6 +904,27 @@ export type ReadCoreDashboard = {
904
904
  ];
905
905
  };
906
906
 
907
+ export type ReadConfiguredPositionDepositRow = {
908
+ positionId: bigint;
909
+ conditionId: `0x${string}`;
910
+ depositedBalance: bigint;
911
+ priceOk: boolean;
912
+ spotPriceE8: bigint;
913
+ twapPriceE8: bigint;
914
+ priceE8: bigint;
915
+ effectivePriceE8: bigint;
916
+ usedFallbackPrice: boolean;
917
+ depositValue: bigint;
918
+ };
919
+
920
+ export type ReadConfiguredPositionDepositsSummary = {
921
+ configuredCount: number;
922
+ pricedCount: number;
923
+ totalDepositedBalance: bigint;
924
+ totalDepositedValue: bigint;
925
+ rows: ReadConfiguredPositionDepositRow[];
926
+ };
927
+
907
928
  /**
908
929
  * Normalized wrapper over `VarlaCore.getTierLiquidationConfig(tier)`.
909
930
  */
@@ -1076,6 +1097,166 @@ export async function readCoreDashboard(params: {
1076
1097
  };
1077
1098
  }
1078
1099
 
1100
+ /**
1101
+ * Reads deposited balances for all oracle-configured positions.
1102
+ *
1103
+ * Uses:
1104
+ * - `oracle.getConfiguredPositions()`
1105
+ * - `positionsToken.balanceOf(core, positionId)`
1106
+ * - `oracle.getPositionSnapshot(positionId)` for pricing
1107
+ * - `oracle.getPriceData(positionId)` for fallback pricing
1108
+ * - `oracle.getConditionId(positionId)` for market mapping
1109
+ */
1110
+ // wraps: VarlaOracle.getConfiguredPositions,ERC1155.balanceOf,VarlaOracle.getPositionSnapshot,VarlaOracle.getPriceData,VarlaOracle.getConditionId
1111
+ export async function readConfiguredPositionDepositsSummary(params: {
1112
+ core: { address: Address };
1113
+ oracle: { address: Address };
1114
+ positionsToken: { address: Address };
1115
+ client: { multicall: (args: any) => Promise<any> };
1116
+ chunkSize?: number;
1117
+ }): Promise<ReadConfiguredPositionDepositsSummary> {
1118
+ const chunkSize = params.chunkSize ?? 256;
1119
+
1120
+ const cfgRes = await multicallChunks({
1121
+ client: params.client as any,
1122
+ contracts: [
1123
+ {
1124
+ address: params.oracle.address,
1125
+ abi: abis.VARLAORACLE_ABI,
1126
+ functionName: "getConfiguredPositions" as const,
1127
+ },
1128
+ ] as any,
1129
+ chunkSize,
1130
+ });
1131
+
1132
+ const cfg0: any = (cfgRes as any[])[0];
1133
+ if (!cfg0 || cfg0.status !== "success" || !Array.isArray(cfg0.result)) {
1134
+ throw new Error(`Configured positions read failed: ${String(cfg0?.error ?? "unknown")}`);
1135
+ }
1136
+
1137
+ const positionIds = [...(cfg0.result as readonly bigint[])];
1138
+ if (positionIds.length === 0) {
1139
+ return {
1140
+ configuredCount: 0,
1141
+ pricedCount: 0,
1142
+ totalDepositedBalance: 0n,
1143
+ totalDepositedValue: 0n,
1144
+ rows: [],
1145
+ };
1146
+ }
1147
+
1148
+ const calls = positionIds.flatMap((pid) => [
1149
+ {
1150
+ address: params.positionsToken.address,
1151
+ abi: erc1155Abi,
1152
+ functionName: "balanceOf" as const,
1153
+ args: [params.core.address, pid] as const,
1154
+ },
1155
+ {
1156
+ address: params.oracle.address,
1157
+ abi: abis.VARLAORACLE_ABI,
1158
+ functionName: "getPositionSnapshot" as const,
1159
+ args: [pid] as const,
1160
+ },
1161
+ {
1162
+ address: params.oracle.address,
1163
+ abi: abis.VARLAORACLE_ABI,
1164
+ functionName: "getPriceData" as const,
1165
+ args: [pid] as const,
1166
+ },
1167
+ {
1168
+ address: params.oracle.address,
1169
+ abi: abis.VARLAORACLE_ABI,
1170
+ functionName: "getConditionId" as const,
1171
+ args: [pid] as const,
1172
+ },
1173
+ ]);
1174
+
1175
+ const res = await multicallChunks({
1176
+ client: params.client as any,
1177
+ contracts: calls as any,
1178
+ chunkSize,
1179
+ });
1180
+
1181
+ const rows: ReadConfiguredPositionDepositRow[] = [];
1182
+ let totalDepositedBalance = 0n;
1183
+ let totalDepositedValue = 0n;
1184
+ let pricedCount = 0;
1185
+
1186
+ for (let i = 0; i < positionIds.length; i++) {
1187
+ const balR: any = (res as any[])[i * 4];
1188
+ const snapR: any = (res as any[])[i * 4 + 1];
1189
+ const priceR: any = (res as any[])[i * 4 + 2];
1190
+ const condR: any = (res as any[])[i * 4 + 3];
1191
+ const pid = positionIds[i]!;
1192
+
1193
+ if (balR?.status !== "success") {
1194
+ throw new Error(
1195
+ `Configured position balance read failed: ${String(balR?.error ?? "unknown")}`,
1196
+ );
1197
+ }
1198
+ if (snapR?.status !== "success") {
1199
+ throw new Error(
1200
+ `Configured position snapshot read failed: ${String(snapR?.error ?? "unknown")}`,
1201
+ );
1202
+ }
1203
+ if (priceR?.status !== "success") {
1204
+ throw new Error(
1205
+ `Configured position priceData read failed: ${String(priceR?.error ?? "unknown")}`,
1206
+ );
1207
+ }
1208
+ if (condR?.status !== "success") {
1209
+ throw new Error(
1210
+ `Configured position condition read failed: ${String(condR?.error ?? "unknown")}`,
1211
+ );
1212
+ }
1213
+
1214
+ const depositedBalance = balR.result as bigint;
1215
+ if (typeof depositedBalance !== "bigint") {
1216
+ throw new Error("Unexpected ERC1155.balanceOf return type");
1217
+ }
1218
+
1219
+ const snap = _normalizeOraclePositionSnapshot(snapR.result, pid);
1220
+ const priceData = _normalizeOraclePriceData(priceR.result, pid);
1221
+ const conditionId = condR.result as `0x${string}`;
1222
+ if (typeof conditionId !== "string" || !conditionId.startsWith("0x")) {
1223
+ throw new Error("Unexpected getConditionId() return shape");
1224
+ }
1225
+
1226
+ const fallbackPriceE8 = _minPositive(priceData.priceE8, priceData.twapE8);
1227
+ const hasSnapshotPrice = snap.priceOk && snap.priceE8 > 0n;
1228
+ const effectivePriceE8 = hasSnapshotPrice ? snap.priceE8 : fallbackPriceE8;
1229
+ const priced = effectivePriceE8 > 0n;
1230
+ const usedFallbackPrice = !hasSnapshotPrice && priced;
1231
+ const depositValue = priced ? (depositedBalance * effectivePriceE8) / _E8 : 0n;
1232
+
1233
+ totalDepositedBalance += depositedBalance;
1234
+ totalDepositedValue += depositValue;
1235
+ if (priced) pricedCount += 1;
1236
+
1237
+ rows.push({
1238
+ positionId: pid,
1239
+ conditionId,
1240
+ depositedBalance,
1241
+ priceOk: snap.priceOk,
1242
+ spotPriceE8: priceData.priceE8,
1243
+ twapPriceE8: priceData.twapE8,
1244
+ priceE8: snap.priceE8,
1245
+ effectivePriceE8,
1246
+ usedFallbackPrice,
1247
+ depositValue,
1248
+ });
1249
+ }
1250
+
1251
+ return {
1252
+ configuredCount: positionIds.length,
1253
+ pricedCount,
1254
+ totalDepositedBalance,
1255
+ totalDepositedValue,
1256
+ rows,
1257
+ };
1258
+ }
1259
+
1079
1260
  export type ReadLiquidationParamsForPosition = {
1080
1261
  positionId: bigint;
1081
1262
  maxLiquidationBonusBps: bigint;
@@ -1590,6 +1771,12 @@ type _OraclePositionSnapshot = {
1590
1771
  earlyClosureFactorWad: bigint;
1591
1772
  };
1592
1773
 
1774
+ type _OraclePriceData = {
1775
+ positionId: bigint;
1776
+ priceE8: bigint;
1777
+ twapE8: bigint;
1778
+ };
1779
+
1593
1780
  function _normalizeOraclePositionSnapshot(
1594
1781
  raw: unknown,
1595
1782
  positionId: bigint,
@@ -1621,6 +1808,31 @@ function _normalizeOraclePositionSnapshot(
1621
1808
  };
1622
1809
  }
1623
1810
 
1811
+ function _normalizeOraclePriceData(raw: unknown, positionId: bigint): _OraclePriceData {
1812
+ const r: any = raw as any;
1813
+ const priceE8 = r.price ?? r[0];
1814
+ const twapE8 = r.twap ?? r[1];
1815
+
1816
+ if (typeof priceE8 !== "bigint" || typeof twapE8 !== "bigint") {
1817
+ throw new Error("Unexpected getPriceData() return shape");
1818
+ }
1819
+
1820
+ return {
1821
+ positionId,
1822
+ priceE8,
1823
+ twapE8,
1824
+ };
1825
+ }
1826
+
1827
+ function _minPositive(a: bigint, b: bigint): bigint {
1828
+ const aOk = a > 0n;
1829
+ const bOk = b > 0n;
1830
+ if (aOk && bOk) return a < b ? a : b;
1831
+ if (aOk) return a;
1832
+ if (bOk) return b;
1833
+ return 0n;
1834
+ }
1835
+
1624
1836
  function _tierDefaultLtv(defaultLtv: ReadDefaultLtvConfig, riskTier: number): bigint {
1625
1837
  if (riskTier === 0) return defaultLtv.conservative;
1626
1838
  if (riskTier === 1) return defaultLtv.moderate;
@@ -275,6 +275,12 @@ export type ReadOracleTiming = {
275
275
  lastUpdated: bigint;
276
276
  };
277
277
 
278
+ export type ReadOracleLowLiquidity = {
279
+ positionId: bigint;
280
+ lowLiquiditySince: bigint;
281
+ lowLiquidityFactorWad: bigint;
282
+ };
283
+
278
284
  export type ReadOracleDashboardRow = {
279
285
  positionId: bigint;
280
286
  snapshot: ReadPositionSnapshot;
@@ -291,6 +297,65 @@ export type ReadOracleDashboard = {
291
297
  rows: ReadOracleDashboardRow[];
292
298
  };
293
299
 
300
+ // wraps: VarlaOracle.getLowLiquiditySince,VarlaOracle.getLowLiquidityFactor
301
+ export async function readManyOracleLowLiquidity(params: {
302
+ oracle: { address: Address };
303
+ client: { multicall: (args: any) => Promise<any> };
304
+ positionIds: readonly bigint[];
305
+ chunkSize?: number;
306
+ }): Promise<ReadOracleLowLiquidity[]> {
307
+ const chunkSize = params.chunkSize ?? 256;
308
+ if (params.positionIds.length === 0) return [];
309
+
310
+ const calls = params.positionIds.flatMap((pid) => [
311
+ {
312
+ address: params.oracle.address,
313
+ abi: abis.VARLAORACLE_ABI,
314
+ functionName: "getLowLiquiditySince" as const,
315
+ args: [pid] as const,
316
+ },
317
+ {
318
+ address: params.oracle.address,
319
+ abi: abis.VARLAORACLE_ABI,
320
+ functionName: "getLowLiquidityFactor" as const,
321
+ args: [pid] as const,
322
+ },
323
+ ]);
324
+
325
+ const res = await multicallChunks({
326
+ client: params.client as any,
327
+ contracts: calls as any,
328
+ chunkSize,
329
+ });
330
+
331
+ const out: ReadOracleLowLiquidity[] = [];
332
+ const stride = 2;
333
+ for (let i = 0; i < params.positionIds.length; i++) {
334
+ const base = i * stride;
335
+ const r0: any = (res as any[])[base + 0];
336
+ const r1: any = (res as any[])[base + 1];
337
+
338
+ if (r0.status !== "success") {
339
+ throw new Error(
340
+ `Oracle getLowLiquiditySince multicall failed: ${String(r0.error ?? "unknown")}`,
341
+ );
342
+ }
343
+ if (r1.status !== "success") {
344
+ throw new Error(
345
+ `Oracle getLowLiquidityFactor multicall failed: ${String(r1.error ?? "unknown")}`,
346
+ );
347
+ }
348
+
349
+ out.push({
350
+ positionId: params.positionIds[i]!,
351
+ lowLiquiditySince: r0.result as bigint,
352
+ lowLiquidityFactorWad: r1.result as bigint,
353
+ });
354
+ }
355
+
356
+ return out;
357
+ }
358
+
294
359
  // wraps: VarlaOracle.getPriceData
295
360
  export async function readOraclePriceData(params: {
296
361
  oracle: {
@@ -1,6 +1,6 @@
1
1
  // Note: explicit .js extension is required for Node ESM resolution.
2
2
 
3
- import type { ReadDefaultLtvConfig, ReadLiquidationConfig } from "./core.js";
3
+ import type { ReadCoreAddresses, ReadDefaultLtvConfig, ReadLiquidationConfig } from "./core.js";
4
4
  import { readCoreDashboard, readDefaultLtvConfig, readLiquidationConfig } from "./core.js";
5
5
  import type { ReadOracleConfig } from "./oracle.js";
6
6
  import { readOracleConfig } from "./oracle.js";
@@ -25,6 +25,7 @@ export type ReadSystemSnapshot = {
25
25
  export type ReadSystemDashboardSnapshot = ReadSystemSnapshot & {
26
26
  poolSharePrice: ReadPoolSharePrice;
27
27
  poolHealthScore: ReadPoolHealthScore;
28
+ coreAddresses: ReadCoreAddresses;
28
29
  };
29
30
 
30
31
  /**
@@ -86,5 +87,6 @@ export async function readSystemDashboardSnapshot(params: {
86
87
  oracle,
87
88
  poolSharePrice: poolDashboard.sharePrice,
88
89
  poolHealthScore: poolDashboard.healthScore,
90
+ coreAddresses: coreDashboard.coreAddresses,
89
91
  };
90
92
  }