@varla/sdk 1.1.1 → 1.2.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":"decode.d.ts","sourceRoot":"","sources":["../../src/events/decode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAG1C,MAAM,MAAM,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,GAAG,EAAE,CAAC;CACb,GAAG,YAAY,EAAE,CAsBjB"}
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/events/decode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAG1C,MAAM,MAAM,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,GAAG,EAAE,CAAA;CAAE,GAAG,YAAY,EAAE,CAsBxF"}
@@ -1 +1 @@
1
- {"version":3,"file":"oracleRegistrySync.d.ts","sourceRoot":"","sources":["../../src/events/oracleRegistrySync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAA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AAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAcF,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,mBAAmB,EAAE,CAAA;CAAE,CAAC,CAwJpE"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Format a WAD (1e18) fixed-point value into a decimal string.
3
+ *
4
+ * - No scientific notation.
5
+ * - Trims trailing zeros.
6
+ * - If `fractionDigits` is provided, it rounds HALF UP to that many digits.
7
+ */
8
+ export declare function formatWad(wad: bigint, params?: {
9
+ decimals?: number;
10
+ fractionDigits?: number;
11
+ }): string;
12
+ /**
13
+ * Format BPS (1e4 = 100%) as a percentage string.
14
+ *
15
+ * Example:
16
+ * - 1500 -> "15%"
17
+ * - 1234 -> "12.34%"
18
+ */
19
+ export declare function formatBps(bps: bigint | number): string;
20
+ /**
21
+ * Format a price with 8 decimals (1e8 = 1.00) into a decimal string.
22
+ *
23
+ * Returns numbers only (no "$" prefix).
24
+ */
25
+ export declare function formatPriceE8(priceE8: bigint, params?: {
26
+ fractionDigits?: number;
27
+ }): string;
28
+ /**
29
+ * Parse a decimal string into a bigint with `decimals` fixed-point precision.
30
+ *
31
+ * - Accepts "123", "123.", "123.45"
32
+ * - Rejects commas and scientific notation.
33
+ */
34
+ export declare function parseUnits(input: string, decimals: number): bigint;
35
+ export declare function parseWad(input: string, decimals?: number): bigint;
36
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,MAAM,CAIR;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAYtD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE3F;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAuBlE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,CAE7D"}
package/dist/format.js ADDED
@@ -0,0 +1,109 @@
1
+ // Note: explicit .js extension is required for Node ESM resolution.
2
+ /**
3
+ * Format a WAD (1e18) fixed-point value into a decimal string.
4
+ *
5
+ * - No scientific notation.
6
+ * - Trims trailing zeros.
7
+ * - If `fractionDigits` is provided, it rounds HALF UP to that many digits.
8
+ */
9
+ export function formatWad(wad, params) {
10
+ const decimals = params?.decimals ?? 18;
11
+ const fractionDigits = params?.fractionDigits;
12
+ return formatUnits(wad, decimals, fractionDigits);
13
+ }
14
+ /**
15
+ * Format BPS (1e4 = 100%) as a percentage string.
16
+ *
17
+ * Example:
18
+ * - 1500 -> "15%"
19
+ * - 1234 -> "12.34%"
20
+ */
21
+ export function formatBps(bps) {
22
+ const b = typeof bps === "bigint" ? bps : BigInt(bps);
23
+ // percent = bps / 100
24
+ const sign = b < 0n ? "-" : "";
25
+ const v = b < 0n ? -b : b;
26
+ const int = v / 100n;
27
+ const frac = v % 100n;
28
+ if (frac === 0n)
29
+ return `${sign}${int}%`;
30
+ const fracStr = frac.toString().padStart(2, "0");
31
+ // trim trailing zeros
32
+ const trimmed = fracStr.replace(/0+$/, "");
33
+ return `${sign}${int}.${trimmed}%`;
34
+ }
35
+ /**
36
+ * Format a price with 8 decimals (1e8 = 1.00) into a decimal string.
37
+ *
38
+ * Returns numbers only (no "$" prefix).
39
+ */
40
+ export function formatPriceE8(priceE8, params) {
41
+ return formatUnits(priceE8, 8, params?.fractionDigits);
42
+ }
43
+ /**
44
+ * Parse a decimal string into a bigint with `decimals` fixed-point precision.
45
+ *
46
+ * - Accepts "123", "123.", "123.45"
47
+ * - Rejects commas and scientific notation.
48
+ */
49
+ export function parseUnits(input, decimals) {
50
+ const s = input.trim();
51
+ if (s.length === 0)
52
+ throw new Error("Empty input");
53
+ if (!Number.isInteger(decimals) || decimals < 0)
54
+ throw new Error("Invalid decimals");
55
+ if (!/^[+-]?\d*(?:\.\d*)?$/.test(s)) {
56
+ throw new Error(`Invalid decimal string: ${input}`);
57
+ }
58
+ const sign = s.startsWith("-") ? -1n : 1n;
59
+ const unsigned = s.startsWith("-") || s.startsWith("+") ? s.slice(1) : s;
60
+ const [intPartRaw, fracPartRaw = ""] = unsigned.split(".");
61
+ const intPart = intPartRaw.length ? intPartRaw : "0";
62
+ const fracPart = fracPartRaw;
63
+ if (fracPart.length > decimals) {
64
+ // We intentionally do NOT round in parse. Callers can round before parsing.
65
+ throw new Error(`Too many decimals (max ${decimals})`);
66
+ }
67
+ const fracPadded = fracPart.padEnd(decimals, "0");
68
+ const combined = `${intPart}${fracPadded}`.replace(/^0+(?=\d)/, "");
69
+ const v = combined.length ? BigInt(combined) : 0n;
70
+ return sign * v;
71
+ }
72
+ export function parseWad(input, decimals = 18) {
73
+ return parseUnits(input, decimals);
74
+ }
75
+ // -----------------
76
+ // Internal helpers
77
+ // -----------------
78
+ function formatUnits(value, decimals, fractionDigits) {
79
+ if (!Number.isInteger(decimals) || decimals < 0)
80
+ throw new Error("Invalid decimals");
81
+ const sign = value < 0n ? "-" : "";
82
+ let v = value < 0n ? -value : value;
83
+ // Optional rounding to fractionDigits
84
+ if (fractionDigits !== undefined) {
85
+ if (!Number.isInteger(fractionDigits) || fractionDigits < 0) {
86
+ throw new Error("Invalid fractionDigits");
87
+ }
88
+ if (fractionDigits < decimals) {
89
+ const drop = decimals - fractionDigits;
90
+ const base = 10n ** BigInt(drop);
91
+ const half = base / 2n;
92
+ // half-up rounding
93
+ v = (v + half) / base;
94
+ // Now v is in units of 10^fractionDigits
95
+ decimals = fractionDigits;
96
+ }
97
+ }
98
+ const base = 10n ** BigInt(decimals);
99
+ const int = v / base;
100
+ const frac = v % base;
101
+ if (decimals === 0)
102
+ return `${sign}${int}`;
103
+ let fracStr = frac.toString().padStart(decimals, "0");
104
+ // Trim trailing zeros
105
+ fracStr = fracStr.replace(/0+$/, "");
106
+ if (fracStr.length === 0)
107
+ return `${sign}${int}`;
108
+ return `${sign}${int}.${fracStr}`;
109
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./types.js";
2
2
  export * from "./contracts.js";
3
3
  export * from "./views/index.js";
4
+ export * from "./format.js";
4
5
  export * from "./events/index.js";
5
6
  export * from "./batch.js";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAG3B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAG3B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,aAAa,CAAC;AAG5B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ export * from "./types.js";
4
4
  export * from "./contracts.js";
5
5
  // Higher-level read helpers (views/facades).
6
6
  export * from "./views/index.js";
7
+ // Pure formatting helpers (no chain calls).
8
+ export * from "./format.js";
7
9
  // Indexer/event helpers.
8
10
  export * from "./events/index.js";
9
11
  // Low-level batching utilities (multicall chunking).
@@ -47,5 +47,78 @@ export declare function readHasRole(params: {
47
47
  isMember: boolean;
48
48
  executionDelay: bigint;
49
49
  }>;
50
+ export type ReadManyHasRoleResult = {
51
+ role: bigint;
52
+ account: Address;
53
+ isMember: boolean;
54
+ executionDelay: bigint;
55
+ };
56
+ /**
57
+ * Batch `hasRole(role, account)` checks.
58
+ *
59
+ * Useful for frontends (permissions gating) and backends (monitoring).
60
+ */
61
+ export declare function readManyHasRole(params: {
62
+ accessManager: {
63
+ address: Address;
64
+ };
65
+ client: {
66
+ multicall: (args: any) => Promise<any>;
67
+ };
68
+ checks: Array<{
69
+ role: bigint;
70
+ account: Address;
71
+ }>;
72
+ chunkSize?: number;
73
+ }): Promise<ReadManyHasRoleResult[]>;
74
+ export type ReadManyTargetFunctionRolesResult = {
75
+ target: Address;
76
+ selector: Hex;
77
+ role: bigint;
78
+ };
79
+ /**
80
+ * Batch `getTargetFunctionRole(target, selector)`.
81
+ */
82
+ export declare function readManyTargetFunctionRoles(params: {
83
+ accessManager: {
84
+ address: Address;
85
+ };
86
+ client: {
87
+ multicall: (args: any) => Promise<any>;
88
+ };
89
+ targets: Array<{
90
+ target: Address;
91
+ selector: Hex;
92
+ }>;
93
+ chunkSize?: number;
94
+ }): Promise<ReadManyTargetFunctionRolesResult[]>;
95
+ export type ReadManyTargetConfigsResult = {
96
+ target: Address;
97
+ selector: Hex;
98
+ role: bigint;
99
+ adminDelay: bigint;
100
+ isClosed: boolean;
101
+ };
102
+ /**
103
+ * Batch read of target function RBAC config.
104
+ *
105
+ * For each {target, selector}, fetches:
106
+ * - getTargetFunctionRole(target, selector)
107
+ * - getTargetAdminDelay(target)
108
+ * - isTargetClosed(target)
109
+ */
110
+ export declare function readManyTargetConfigs(params: {
111
+ accessManager: {
112
+ address: Address;
113
+ };
114
+ client: {
115
+ multicall: (args: any) => Promise<any>;
116
+ };
117
+ targets: Array<{
118
+ target: Address;
119
+ selector: Hex;
120
+ }>;
121
+ chunkSize?: number;
122
+ }): Promise<ReadManyTargetConfigsResult[]>;
50
123
  export {};
51
124
  //# sourceMappingURL=accessManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accessManager.d.ts","sourceRoot":"","sources":["../../src/views/accessManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE;QAEJ,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QAC3C,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QAG5C,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACnF,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACpE,iBAAiB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACzE,eAAe,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAA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AE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IACpC,MAAM,EAAE;QAAE,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;IACnD,OAAO,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,2BAA2B,EAAE,CAAC,CA+DzC"}
@@ -1,4 +1,6 @@
1
1
  // Note: explicit .js extension is required for Node ESM resolution.
2
+ import { multicallChunks } from "../batch.js";
3
+ import { abis } from "../generated.js";
2
4
  function toBigInt(v) {
3
5
  return typeof v === "bigint" ? v : BigInt(v);
4
6
  }
@@ -42,3 +44,135 @@ export async function readHasRole(params) {
42
44
  const executionDelay = r.executionDelay ?? r[1];
43
45
  return { isMember, executionDelay: BigInt(executionDelay) };
44
46
  }
47
+ /**
48
+ * Batch `hasRole(role, account)` checks.
49
+ *
50
+ * Useful for frontends (permissions gating) and backends (monitoring).
51
+ */
52
+ export async function readManyHasRole(params) {
53
+ const chunkSize = params.chunkSize ?? 256;
54
+ if (params.checks.length === 0)
55
+ return [];
56
+ const res = await multicallChunks({
57
+ client: params.client,
58
+ contracts: params.checks.map((c) => ({
59
+ address: params.accessManager.address,
60
+ abi: abis.VARLAACCESSMANAGER_ABI,
61
+ functionName: "hasRole",
62
+ args: [c.role, c.account],
63
+ })),
64
+ chunkSize,
65
+ });
66
+ const out = [];
67
+ for (let i = 0; i < res.length; i++) {
68
+ const r = res[i];
69
+ if (r.status !== "success") {
70
+ throw new Error(`AccessManager hasRole multicall failed: ${String(r.error ?? "unknown")}`);
71
+ }
72
+ const v = r.result;
73
+ const isMember = v.isMember ?? v[0];
74
+ const executionDelay = v.executionDelay ?? v[1];
75
+ out.push({
76
+ role: params.checks[i].role,
77
+ account: params.checks[i].account,
78
+ isMember,
79
+ executionDelay: BigInt(executionDelay),
80
+ });
81
+ }
82
+ return out;
83
+ }
84
+ /**
85
+ * Batch `getTargetFunctionRole(target, selector)`.
86
+ */
87
+ export async function readManyTargetFunctionRoles(params) {
88
+ const chunkSize = params.chunkSize ?? 256;
89
+ if (params.targets.length === 0)
90
+ return [];
91
+ const calls = params.targets.map((t) => ({
92
+ address: params.accessManager.address,
93
+ abi: abis.VARLAACCESSMANAGER_ABI,
94
+ functionName: "getTargetFunctionRole",
95
+ args: [t.target, t.selector],
96
+ }));
97
+ const res = await multicallChunks({
98
+ client: params.client,
99
+ contracts: calls,
100
+ chunkSize,
101
+ });
102
+ const out = [];
103
+ for (let i = 0; i < res.length; i++) {
104
+ const r = res[i];
105
+ if (r.status !== "success") {
106
+ throw new Error(`AccessManager getTargetFunctionRole multicall failed: ${String(r.error ?? "unknown")}`);
107
+ }
108
+ out.push({
109
+ target: params.targets[i].target,
110
+ selector: params.targets[i].selector,
111
+ role: toBigInt(r.result),
112
+ });
113
+ }
114
+ return out;
115
+ }
116
+ /**
117
+ * Batch read of target function RBAC config.
118
+ *
119
+ * For each {target, selector}, fetches:
120
+ * - getTargetFunctionRole(target, selector)
121
+ * - getTargetAdminDelay(target)
122
+ * - isTargetClosed(target)
123
+ */
124
+ export async function readManyTargetConfigs(params) {
125
+ const chunkSize = params.chunkSize ?? 256;
126
+ if (params.targets.length === 0)
127
+ return [];
128
+ const calls = params.targets.flatMap((t) => [
129
+ {
130
+ address: params.accessManager.address,
131
+ abi: abis.VARLAACCESSMANAGER_ABI,
132
+ functionName: "getTargetFunctionRole",
133
+ args: [t.target, t.selector],
134
+ },
135
+ {
136
+ address: params.accessManager.address,
137
+ abi: abis.VARLAACCESSMANAGER_ABI,
138
+ functionName: "getTargetAdminDelay",
139
+ args: [t.target],
140
+ },
141
+ {
142
+ address: params.accessManager.address,
143
+ abi: abis.VARLAACCESSMANAGER_ABI,
144
+ functionName: "isTargetClosed",
145
+ args: [t.target],
146
+ },
147
+ ]);
148
+ const res = await multicallChunks({
149
+ client: params.client,
150
+ contracts: calls,
151
+ chunkSize,
152
+ });
153
+ const out = [];
154
+ const stride = 3;
155
+ for (let i = 0; i < params.targets.length; i++) {
156
+ const base = i * stride;
157
+ const rRole = res[base + 0];
158
+ const rDelay = res[base + 1];
159
+ const rClosed = res[base + 2];
160
+ if (rRole.status !== "success") {
161
+ throw new Error(`AccessManager getTargetFunctionRole multicall failed: ${String(rRole.error ?? "unknown")}`);
162
+ }
163
+ if (rDelay.status !== "success") {
164
+ throw new Error(`AccessManager getTargetAdminDelay multicall failed: ${String(rDelay.error ?? "unknown")}`);
165
+ }
166
+ if (rClosed.status !== "success") {
167
+ throw new Error(`AccessManager isTargetClosed multicall failed: ${String(rClosed.error ?? "unknown")}`);
168
+ }
169
+ out.push({
170
+ target: params.targets[i].target,
171
+ selector: params.targets[i].selector,
172
+ role: toBigInt(rRole.result),
173
+ adminDelay: toBigInt(rDelay.result),
174
+ isClosed: rClosed.result,
175
+ });
176
+ }
177
+ return out;
178
+ }
@@ -30,4 +30,154 @@ export declare function readAccountPositions(params: {
30
30
  positionIds: bigint[];
31
31
  balances: bigint[];
32
32
  }>;
33
+ export type ReadHealthFactor = {
34
+ healthFactor: bigint;
35
+ canBeLiquidated: boolean;
36
+ };
37
+ /**
38
+ * Read the user's health factor and whether liquidation is currently allowed.
39
+ *
40
+ * Normalizes `VarlaCore.getHealthFactor(user)` tuple return.
41
+ */
42
+ export declare function readHealthFactor(params: {
43
+ core: {
44
+ read: {
45
+ getHealthFactor: (args: readonly [Address]) => Promise<unknown>;
46
+ };
47
+ };
48
+ user: Address;
49
+ }): Promise<ReadHealthFactor>;
50
+ export type ReadLiquidationConfig = {
51
+ targetHealthFactor: bigint;
52
+ healthFactorForMaxBonus: bigint;
53
+ liquidationBonusFactorBps: bigint;
54
+ dustThreshold: bigint;
55
+ collateralDustThreshold: bigint;
56
+ };
57
+ /**
58
+ * Normalized wrapper over `VarlaCore.getLiquidationConfig()`.
59
+ */
60
+ export declare function readLiquidationConfig(params: {
61
+ core: {
62
+ read: {
63
+ getLiquidationConfig: () => Promise<unknown>;
64
+ };
65
+ };
66
+ }): Promise<ReadLiquidationConfig>;
67
+ export type ReadDefaultLtvConfig = {
68
+ conservative: bigint;
69
+ moderate: bigint;
70
+ risk: bigint;
71
+ };
72
+ /**
73
+ * Normalized wrapper over `VarlaCore.getDefaultLtvConfig()`.
74
+ */
75
+ export declare function readDefaultLtvConfig(params: {
76
+ core: {
77
+ read: {
78
+ getDefaultLtvConfig: () => Promise<unknown>;
79
+ };
80
+ };
81
+ }): Promise<ReadDefaultLtvConfig>;
82
+ export type ReadTierLiquidationConfig = {
83
+ tier: number;
84
+ maxLiquidationBonusBps: bigint;
85
+ liquidationFeeBps: bigint;
86
+ };
87
+ /**
88
+ * Normalized wrapper over `VarlaCore.getTierLiquidationConfig(tier)`.
89
+ */
90
+ export declare function readTierLiquidationConfig(params: {
91
+ core: {
92
+ read: {
93
+ getTierLiquidationConfig: (args: readonly [number]) => Promise<unknown>;
94
+ };
95
+ };
96
+ tier: number;
97
+ }): Promise<ReadTierLiquidationConfig>;
98
+ export type ReadLiquidationParamsForPosition = {
99
+ positionId: bigint;
100
+ maxLiquidationBonusBps: bigint;
101
+ liquidationFeeBps: bigint;
102
+ };
103
+ /**
104
+ * Normalized wrapper over `VarlaCore.getLiquidationParamsForPosition(positionId)`.
105
+ */
106
+ export declare function readLiquidationParamsForPosition(params: {
107
+ core: {
108
+ read: {
109
+ getLiquidationParamsForPosition: (args: readonly [bigint]) => Promise<unknown>;
110
+ };
111
+ };
112
+ positionId: bigint;
113
+ }): Promise<ReadLiquidationParamsForPosition>;
114
+ export type ReadPositionLtvOverride = {
115
+ positionId: bigint;
116
+ isSet: boolean;
117
+ ltv: bigint;
118
+ };
119
+ /**
120
+ * Normalized wrapper over `VarlaCore.getPositionLtvOverride(positionId)`.
121
+ */
122
+ export declare function readPositionLtvOverride(params: {
123
+ core: {
124
+ read: {
125
+ getPositionLtvOverride: (args: readonly [bigint]) => Promise<unknown>;
126
+ };
127
+ };
128
+ positionId: bigint;
129
+ }): Promise<ReadPositionLtvOverride>;
130
+ /**
131
+ * Thin wrapper over `VarlaCore.getLtvForPosition(positionId)`.
132
+ *
133
+ * This is the *effective* LTV for the position (includes early-closure factor and overrides).
134
+ */
135
+ export declare function readLtvForPosition(params: {
136
+ core: {
137
+ read: {
138
+ getLtvForPosition: (args: readonly [bigint]) => Promise<bigint>;
139
+ };
140
+ };
141
+ positionId: bigint;
142
+ }): Promise<{
143
+ positionId: bigint;
144
+ ltvWad: bigint;
145
+ }>;
146
+ /**
147
+ * Thin wrapper over `VarlaCore.getLiquidationBonusBps(positionId, healthFactor)`.
148
+ */
149
+ export declare function readLiquidationBonusBps(params: {
150
+ core: {
151
+ read: {
152
+ getLiquidationBonusBps: (args: readonly [bigint, bigint]) => Promise<bigint>;
153
+ };
154
+ };
155
+ positionId: bigint;
156
+ healthFactor: bigint;
157
+ }): Promise<{
158
+ positionId: bigint;
159
+ healthFactor: bigint;
160
+ bonusBps: bigint;
161
+ }>;
162
+ export type ReadManyLiquidationBonusBpsRow = {
163
+ positionId: bigint;
164
+ /** bonusesBps aligned to input `healthFactors` order */
165
+ bonusesBps: bigint[];
166
+ };
167
+ /**
168
+ * Computes a (positionIds × healthFactors) grid of liquidation bonuses.
169
+ *
170
+ * Useful for UIs that need to visualize liquidation incentive curves.
171
+ */
172
+ export declare function readManyLiquidationBonusBps(params: {
173
+ core: {
174
+ address: Address;
175
+ };
176
+ client: {
177
+ multicall: (args: any) => Promise<any>;
178
+ };
179
+ positionIds: readonly bigint[];
180
+ healthFactors: readonly bigint[];
181
+ chunkSize?: number;
182
+ }): Promise<ReadManyLiquidationBonusBpsRow[]>;
33
183
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/views/core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EA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EG;AACH,wBAAsB,uBAAuB,CAAC,MAAM,EAAE;IACpD,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,sBAAsB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;SAC9E,CAAC;KACH,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAM1E;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,MAAM,EAAE;IACxD,IAAI,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3B,MAAM,EAAE;QAAE,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;IACnD,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,8BAA8B,EAAE,CAAC,CA2C5C"}
@@ -48,3 +48,159 @@ export async function readAccountPositions(params) {
48
48
  }
49
49
  return { positionIds, balances };
50
50
  }
51
+ /**
52
+ * Read the user's health factor and whether liquidation is currently allowed.
53
+ *
54
+ * Normalizes `VarlaCore.getHealthFactor(user)` tuple return.
55
+ */
56
+ export async function readHealthFactor(params) {
57
+ const raw = await params.core.read.getHealthFactor([params.user]);
58
+ const r = raw;
59
+ const healthFactor = r.healthFactor ?? r[0];
60
+ const canBeLiquidated = r.canBeLiquidated ?? r[1];
61
+ if (typeof healthFactor !== "bigint" || typeof canBeLiquidated !== "boolean") {
62
+ throw new Error("Unexpected getHealthFactor() return shape");
63
+ }
64
+ return { healthFactor, canBeLiquidated };
65
+ }
66
+ /**
67
+ * Normalized wrapper over `VarlaCore.getLiquidationConfig()`.
68
+ */
69
+ export async function readLiquidationConfig(params) {
70
+ const raw = await params.core.read.getLiquidationConfig();
71
+ const r = raw;
72
+ const targetHealthFactor = r.targetHealthFactor ?? r[0];
73
+ const healthFactorForMaxBonus = r.healthFactorForMaxBonus ?? r[1];
74
+ const liquidationBonusFactorBps = r.liquidationBonusFactorBps ?? r[2];
75
+ const dustThreshold = r.dustThreshold ?? r[3];
76
+ const collateralDustThreshold = r.collateralDustThreshold ?? r[4];
77
+ if (typeof targetHealthFactor !== "bigint" ||
78
+ typeof healthFactorForMaxBonus !== "bigint" ||
79
+ typeof liquidationBonusFactorBps !== "bigint" ||
80
+ typeof dustThreshold !== "bigint" ||
81
+ typeof collateralDustThreshold !== "bigint") {
82
+ throw new Error("Unexpected getLiquidationConfig() return shape");
83
+ }
84
+ return {
85
+ targetHealthFactor,
86
+ healthFactorForMaxBonus,
87
+ liquidationBonusFactorBps,
88
+ dustThreshold,
89
+ collateralDustThreshold,
90
+ };
91
+ }
92
+ /**
93
+ * Normalized wrapper over `VarlaCore.getDefaultLtvConfig()`.
94
+ */
95
+ export async function readDefaultLtvConfig(params) {
96
+ const raw = await params.core.read.getDefaultLtvConfig();
97
+ const r = raw;
98
+ const conservative = r.conservative ?? r[0];
99
+ const moderate = r.moderate ?? r[1];
100
+ const risk = r.risk ?? r[2];
101
+ if (typeof conservative !== "bigint" ||
102
+ typeof moderate !== "bigint" ||
103
+ typeof risk !== "bigint") {
104
+ throw new Error("Unexpected getDefaultLtvConfig() return shape");
105
+ }
106
+ return { conservative, moderate, risk };
107
+ }
108
+ /**
109
+ * Normalized wrapper over `VarlaCore.getTierLiquidationConfig(tier)`.
110
+ */
111
+ export async function readTierLiquidationConfig(params) {
112
+ const raw = await params.core.read.getTierLiquidationConfig([params.tier]);
113
+ const r = raw;
114
+ const maxLiquidationBonusBps = r.maxLiquidationBonusBps ?? r[0];
115
+ const liquidationFeeBps = r.liquidationFeeBps ?? r[1];
116
+ if (typeof maxLiquidationBonusBps !== "bigint" || typeof liquidationFeeBps !== "bigint") {
117
+ throw new Error("Unexpected getTierLiquidationConfig() return shape");
118
+ }
119
+ return { tier: params.tier, maxLiquidationBonusBps, liquidationFeeBps };
120
+ }
121
+ /**
122
+ * Normalized wrapper over `VarlaCore.getLiquidationParamsForPosition(positionId)`.
123
+ */
124
+ export async function readLiquidationParamsForPosition(params) {
125
+ const raw = await params.core.read.getLiquidationParamsForPosition([params.positionId]);
126
+ const r = raw;
127
+ const maxLiquidationBonusBps = r.maxLiquidationBonusBps ?? r[0];
128
+ const liquidationFeeBps = r.liquidationFeeBps ?? r[1];
129
+ if (typeof maxLiquidationBonusBps !== "bigint" || typeof liquidationFeeBps !== "bigint") {
130
+ throw new Error("Unexpected getLiquidationParamsForPosition() return shape");
131
+ }
132
+ return { positionId: params.positionId, maxLiquidationBonusBps, liquidationFeeBps };
133
+ }
134
+ /**
135
+ * Normalized wrapper over `VarlaCore.getPositionLtvOverride(positionId)`.
136
+ */
137
+ export async function readPositionLtvOverride(params) {
138
+ const raw = await params.core.read.getPositionLtvOverride([params.positionId]);
139
+ const r = raw;
140
+ const isSet = r.isSet ?? r[0];
141
+ const ltv = r.ltv ?? r[1];
142
+ if (typeof isSet !== "boolean" || typeof ltv !== "bigint") {
143
+ throw new Error("Unexpected getPositionLtvOverride() return shape");
144
+ }
145
+ return { positionId: params.positionId, isSet, ltv };
146
+ }
147
+ /**
148
+ * Thin wrapper over `VarlaCore.getLtvForPosition(positionId)`.
149
+ *
150
+ * This is the *effective* LTV for the position (includes early-closure factor and overrides).
151
+ */
152
+ export async function readLtvForPosition(params) {
153
+ const ltvWad = await params.core.read.getLtvForPosition([params.positionId]);
154
+ return { positionId: params.positionId, ltvWad };
155
+ }
156
+ /**
157
+ * Thin wrapper over `VarlaCore.getLiquidationBonusBps(positionId, healthFactor)`.
158
+ */
159
+ export async function readLiquidationBonusBps(params) {
160
+ const bonusBps = await params.core.read.getLiquidationBonusBps([
161
+ params.positionId,
162
+ params.healthFactor,
163
+ ]);
164
+ return { positionId: params.positionId, healthFactor: params.healthFactor, bonusBps };
165
+ }
166
+ /**
167
+ * Computes a (positionIds × healthFactors) grid of liquidation bonuses.
168
+ *
169
+ * Useful for UIs that need to visualize liquidation incentive curves.
170
+ */
171
+ export async function readManyLiquidationBonusBps(params) {
172
+ const chunkSize = params.chunkSize ?? 256;
173
+ if (params.positionIds.length === 0)
174
+ return [];
175
+ if (params.healthFactors.length === 0) {
176
+ return params.positionIds.map((positionId) => ({ positionId, bonusesBps: [] }));
177
+ }
178
+ const calls = params.positionIds.flatMap((pid) => params.healthFactors.map((hf) => ({
179
+ address: params.core.address,
180
+ abi: abis.VARLACORE_ABI,
181
+ functionName: "getLiquidationBonusBps",
182
+ args: [pid, hf],
183
+ })));
184
+ const res = await multicallChunks({
185
+ client: params.client,
186
+ contracts: calls,
187
+ chunkSize,
188
+ });
189
+ const stride = params.healthFactors.length;
190
+ const out = [];
191
+ for (let i = 0; i < params.positionIds.length; i++) {
192
+ const bonusesBps = [];
193
+ for (let j = 0; j < stride; j++) {
194
+ const r = res[i * stride + j];
195
+ if (r.status !== "success") {
196
+ throw new Error(`Core getLiquidationBonusBps multicall failed: ${String(r.error ?? "unknown")}`);
197
+ }
198
+ if (typeof r.result !== "bigint") {
199
+ throw new Error("Unexpected getLiquidationBonusBps return type");
200
+ }
201
+ bonusesBps.push(r.result);
202
+ }
203
+ out.push({ positionId: params.positionIds[i], bonusesBps });
204
+ }
205
+ return out;
206
+ }
@@ -23,4 +23,54 @@ export type ReadOracleRegistryParams = {
23
23
  * - `getConfiguredPositionAt(i)` via multicall
24
24
  */
25
25
  export declare function readOracleRegistry(params: ReadOracleRegistryParams): Promise<bigint[]>;
26
+ export type ReadOracleConfig = {
27
+ maxStaleness: bigint;
28
+ liquidationGracePeriod: bigint;
29
+ defaultEarlyClosureWindow: bigint;
30
+ };
31
+ /**
32
+ * Reads key global oracle config values used by UIs and monitoring.
33
+ */
34
+ export declare function readOracleConfig(params: {
35
+ oracle: {
36
+ read: {
37
+ maxStaleness: () => Promise<bigint>;
38
+ liquidationGracePeriod: () => Promise<bigint>;
39
+ defaultEarlyClosureWindow: () => Promise<bigint>;
40
+ };
41
+ };
42
+ }): Promise<ReadOracleConfig>;
43
+ export type ReadPositionSnapshot = {
44
+ positionId: bigint;
45
+ priceOk: boolean;
46
+ priceE8: bigint;
47
+ manuallyInvalidated: boolean;
48
+ riskTier: number;
49
+ earlyClosureFactorWad: bigint;
50
+ lastRecoveryFromStale: bigint;
51
+ };
52
+ /**
53
+ * Normalized wrapper over `VarlaOracle.getPositionSnapshot(positionId)`.
54
+ */
55
+ export declare function readPositionSnapshot(params: {
56
+ oracle: {
57
+ read: {
58
+ getPositionSnapshot: (args: readonly [bigint]) => Promise<unknown>;
59
+ };
60
+ };
61
+ positionId: bigint;
62
+ }): Promise<ReadPositionSnapshot>;
63
+ /**
64
+ * Multicall-chunked `getPositionSnapshot` for many ids.
65
+ */
66
+ export declare function readManyPositionSnapshots(params: {
67
+ oracle: {
68
+ address: Address;
69
+ };
70
+ client: {
71
+ multicall: (args: any) => Promise<any>;
72
+ };
73
+ positionIds: readonly bigint[];
74
+ chunkSize?: number;
75
+ }): Promise<ReadPositionSnapshot[]>;
26
76
  //# sourceMappingURL=oracle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oracle.d.ts","sourceRoot":"","sources":["../../src/views/oracle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAIpC,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE;QACN,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE;YACJ,2BAA2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,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;YAC9C,yBAAyB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;SAClD,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAO5B;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAkCF;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IACjD,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,mBAAmB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;SACpE,CAAC;KACH,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAGhC;AAED;;GAEG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE;IACtD,MAAM,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAC7B,MAAM,EAAE;QAAE,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;IACnD,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC,CA4BlC"}
@@ -39,3 +39,75 @@ export async function readOracleRegistry(params) {
39
39
  }
40
40
  return ids;
41
41
  }
42
+ /**
43
+ * Reads key global oracle config values used by UIs and monitoring.
44
+ */
45
+ export async function readOracleConfig(params) {
46
+ const [maxStaleness, liquidationGracePeriod, defaultEarlyClosureWindow] = await Promise.all([
47
+ params.oracle.read.maxStaleness(),
48
+ params.oracle.read.liquidationGracePeriod(),
49
+ params.oracle.read.defaultEarlyClosureWindow(),
50
+ ]);
51
+ return { maxStaleness, liquidationGracePeriod, defaultEarlyClosureWindow };
52
+ }
53
+ function normalizePositionSnapshot(raw, positionId) {
54
+ const r = raw;
55
+ const priceOk = r.priceOk ?? r[0];
56
+ const priceE8 = r.priceE8 ?? r[1];
57
+ const manuallyInvalidated = r.manuallyInvalidated ?? r[2];
58
+ const riskTier = r.riskTier ?? r[3];
59
+ const earlyClosureFactorWad = r.earlyClosureFactorWad ?? r[4];
60
+ const lastRecoveryFromStale = r.lastRecoveryFromStale_ ?? r.lastRecoveryFromStale ?? r[5];
61
+ if (typeof priceOk !== "boolean" ||
62
+ typeof priceE8 !== "bigint" ||
63
+ typeof manuallyInvalidated !== "boolean" ||
64
+ (typeof riskTier !== "number" && typeof riskTier !== "bigint") ||
65
+ typeof earlyClosureFactorWad !== "bigint" ||
66
+ typeof lastRecoveryFromStale !== "bigint") {
67
+ throw new Error("Unexpected getPositionSnapshot() return shape");
68
+ }
69
+ return {
70
+ positionId,
71
+ priceOk,
72
+ priceE8,
73
+ manuallyInvalidated,
74
+ riskTier: Number(riskTier),
75
+ earlyClosureFactorWad,
76
+ lastRecoveryFromStale,
77
+ };
78
+ }
79
+ /**
80
+ * Normalized wrapper over `VarlaOracle.getPositionSnapshot(positionId)`.
81
+ */
82
+ export async function readPositionSnapshot(params) {
83
+ const raw = await params.oracle.read.getPositionSnapshot([params.positionId]);
84
+ return normalizePositionSnapshot(raw, params.positionId);
85
+ }
86
+ /**
87
+ * Multicall-chunked `getPositionSnapshot` for many ids.
88
+ */
89
+ export async function readManyPositionSnapshots(params) {
90
+ const chunkSize = params.chunkSize ?? 256;
91
+ if (params.positionIds.length === 0)
92
+ return [];
93
+ const calls = params.positionIds.map((pid) => ({
94
+ address: params.oracle.address,
95
+ abi: abis.VARLAORACLE_ABI,
96
+ functionName: "getPositionSnapshot",
97
+ args: [pid],
98
+ }));
99
+ const res = await multicallChunks({
100
+ client: params.client,
101
+ contracts: calls,
102
+ chunkSize,
103
+ });
104
+ const out = [];
105
+ for (let i = 0; i < res.length; i++) {
106
+ const r = res[i];
107
+ if (r.status !== "success") {
108
+ throw new Error(`Oracle getPositionSnapshot multicall failed: ${String(r.error ?? "unknown")}`);
109
+ }
110
+ out.push(normalizePositionSnapshot(r.result, params.positionIds[i]));
111
+ }
112
+ return out;
113
+ }
@@ -1,10 +1,4 @@
1
- export declare function readPoolSnapshot(params: {
2
- pool: {
3
- read: {
4
- getPoolStats: () => Promise<unknown>;
5
- };
6
- };
7
- }): Promise<{
1
+ export type ReadPoolSnapshot = {
8
2
  totalAssets: bigint;
9
3
  totalBorrowed: bigint;
10
4
  available: bigint;
@@ -12,5 +6,46 @@ export declare function readPoolSnapshot(params: {
12
6
  borrowRate: bigint;
13
7
  supplyAPY: bigint;
14
8
  borrowIndex: bigint;
15
- }>;
9
+ };
10
+ export declare function readPoolSnapshot(params: {
11
+ pool: {
12
+ read: {
13
+ getPoolStats: () => Promise<unknown>;
14
+ };
15
+ };
16
+ }): Promise<ReadPoolSnapshot>;
17
+ export type ReadPoolCaps = {
18
+ depositCap: bigint;
19
+ borrowCap: bigint;
20
+ };
21
+ /**
22
+ * Reads depositCap/borrowCap (useful for frontends + monitoring).
23
+ */
24
+ export declare function readPoolCaps(params: {
25
+ pool: {
26
+ read: {
27
+ depositCap: () => Promise<bigint>;
28
+ borrowCap: () => Promise<bigint>;
29
+ };
30
+ };
31
+ }): Promise<ReadPoolCaps>;
32
+ export type ReadPoolAccounting = {
33
+ reserveBalance: bigint;
34
+ scaledTotalBorrowed: bigint;
35
+ borrowIndex: bigint;
36
+ lastUpdateTimestamp: bigint;
37
+ };
38
+ /**
39
+ * Reads accounting/index variables that are commonly required in analytics.
40
+ */
41
+ export declare function readPoolAccounting(params: {
42
+ pool: {
43
+ read: {
44
+ reserveBalance: () => Promise<bigint>;
45
+ scaledTotalBorrowed: () => Promise<bigint>;
46
+ borrowIndex: () => Promise<bigint>;
47
+ lastUpdateTimestamp: () => Promise<bigint | number>;
48
+ };
49
+ };
50
+ }): Promise<ReadPoolAccounting>;
16
51
  //# sourceMappingURL=pool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/views/pool.ts"],"names":[],"mappings":"AAEA,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;SACtC,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAmCD"}
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/views/pool.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;SACtC,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmC5B;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE;IACzC,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;YAClC,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;SAClC,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC,YAAY,CAAC,CAMxB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE;IAC/C,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;YACtC,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;YAC3C,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;YACnC,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;SACrD,CAAC;KACH,CAAC;CACH,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAgB9B"}
@@ -30,3 +30,30 @@ export async function readPoolSnapshot(params) {
30
30
  borrowIndex,
31
31
  };
32
32
  }
33
+ /**
34
+ * Reads depositCap/borrowCap (useful for frontends + monitoring).
35
+ */
36
+ export async function readPoolCaps(params) {
37
+ const [depositCap, borrowCap] = await Promise.all([
38
+ params.pool.read.depositCap(),
39
+ params.pool.read.borrowCap(),
40
+ ]);
41
+ return { depositCap, borrowCap };
42
+ }
43
+ /**
44
+ * Reads accounting/index variables that are commonly required in analytics.
45
+ */
46
+ export async function readPoolAccounting(params) {
47
+ const [reserveBalance, scaledTotalBorrowed, borrowIndex, lastUpdateTimestamp] = await Promise.all([
48
+ params.pool.read.reserveBalance(),
49
+ params.pool.read.scaledTotalBorrowed(),
50
+ params.pool.read.borrowIndex(),
51
+ params.pool.read.lastUpdateTimestamp(),
52
+ ]);
53
+ return {
54
+ reserveBalance,
55
+ scaledTotalBorrowed,
56
+ borrowIndex,
57
+ lastUpdateTimestamp: BigInt(lastUpdateTimestamp),
58
+ };
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varla/sdk",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,