@varla/sdk 1.2.0 → 1.10.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/README.md +84 -0
- package/dist/abi/full/VarlaCore.d.ts +15 -0
- package/dist/abi/full/VarlaCore.d.ts.map +1 -1
- package/dist/abi/full/VarlaCore.js +19 -0
- package/dist/generated.d.ts +15 -0
- package/dist/generated.d.ts.map +1 -1
- package/dist/views/accessManager.d.ts.map +1 -1
- package/dist/views/accessManager.js +7 -0
- package/dist/views/adapters.d.ts.map +1 -1
- package/dist/views/adapters.js +1 -0
- package/dist/views/admin.d.ts +7 -1
- package/dist/views/admin.d.ts.map +1 -1
- package/dist/views/admin.js +25 -1
- package/dist/views/core.d.ts +226 -0
- package/dist/views/core.d.ts.map +1 -1
- package/dist/views/core.js +304 -0
- package/dist/views/index.d.ts +1 -0
- package/dist/views/index.d.ts.map +1 -1
- package/dist/views/index.js +1 -0
- package/dist/views/liquidators.d.ts.map +1 -1
- package/dist/views/liquidators.js +3 -0
- package/dist/views/oracle.d.ts +238 -1
- package/dist/views/oracle.d.ts.map +1 -1
- package/dist/views/oracle.js +323 -0
- package/dist/views/pool.d.ts +46 -0
- package/dist/views/pool.d.ts.map +1 -1
- package/dist/views/pool.js +33 -0
- package/dist/views/system.d.ts +24 -0
- package/dist/views/system.d.ts.map +1 -0
- package/dist/views/system.js +23 -0
- package/package.json +17 -1
package/dist/views/core.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ export type ReadAccountSnapshot = {
|
|
|
6
6
|
healthFactor: bigint;
|
|
7
7
|
maxBorrow: bigint;
|
|
8
8
|
};
|
|
9
|
+
export type ReadCoreAddresses = {
|
|
10
|
+
collateralToken: Address;
|
|
11
|
+
positionsToken: Address;
|
|
12
|
+
pool: Address;
|
|
13
|
+
oracle: Address;
|
|
14
|
+
collateralDecimals: number;
|
|
15
|
+
};
|
|
9
16
|
export declare function readAccountSnapshot(params: {
|
|
10
17
|
core: {
|
|
11
18
|
read: {
|
|
@@ -14,6 +21,148 @@ export declare function readAccountSnapshot(params: {
|
|
|
14
21
|
};
|
|
15
22
|
user: Address;
|
|
16
23
|
}): Promise<ReadAccountSnapshot>;
|
|
24
|
+
/**
|
|
25
|
+
* Read VarlaCore wiring + token metadata that most consumers need.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readCoreAddresses(params: {
|
|
28
|
+
core: {
|
|
29
|
+
read: {
|
|
30
|
+
collateralToken: () => Promise<Address>;
|
|
31
|
+
positionsToken: () => Promise<Address>;
|
|
32
|
+
pool: () => Promise<Address>;
|
|
33
|
+
oracle: () => Promise<Address>;
|
|
34
|
+
collateralDecimals: () => Promise<number | bigint>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}): Promise<ReadCoreAddresses>;
|
|
38
|
+
export type ReadMaxPositionsConfig = {
|
|
39
|
+
maxPositions: bigint;
|
|
40
|
+
minMaxPositions: bigint;
|
|
41
|
+
maxMaxPositions: bigint;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Read max-positions safety bounds + current value (useful for deposit UX).
|
|
45
|
+
*/
|
|
46
|
+
export declare function readMaxPositionsConfig(params: {
|
|
47
|
+
core: {
|
|
48
|
+
read: {
|
|
49
|
+
maxPositions: () => Promise<bigint>;
|
|
50
|
+
minMaxPositions: () => Promise<bigint>;
|
|
51
|
+
maxMaxPositions: () => Promise<bigint>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}): Promise<ReadMaxPositionsConfig>;
|
|
55
|
+
export type ReadAccountPositionsFull = {
|
|
56
|
+
user: Address;
|
|
57
|
+
positionIds: bigint[];
|
|
58
|
+
balances: bigint[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Single-call alternative to `readAccountPositions` (no multicall).
|
|
62
|
+
*/
|
|
63
|
+
export declare function readAccountPositionsFull(params: {
|
|
64
|
+
core: {
|
|
65
|
+
read: {
|
|
66
|
+
getPositions: (args: readonly [Address]) => Promise<unknown>;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
user: Address;
|
|
70
|
+
}): Promise<ReadAccountPositionsFull>;
|
|
71
|
+
export type ReadPositionBalances = {
|
|
72
|
+
user: Address;
|
|
73
|
+
positionIds: bigint[];
|
|
74
|
+
balances: bigint[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Efficiently hydrate balances for a known list of ids.
|
|
78
|
+
*/
|
|
79
|
+
export declare function readPositionBalances(params: {
|
|
80
|
+
core: {
|
|
81
|
+
read: {
|
|
82
|
+
getPositionBalances: (args: readonly [Address, readonly bigint[]]) => Promise<readonly bigint[]>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
user: Address;
|
|
86
|
+
positionIds: readonly bigint[];
|
|
87
|
+
}): Promise<ReadPositionBalances>;
|
|
88
|
+
export type ReadBorrowerState = {
|
|
89
|
+
user: Address;
|
|
90
|
+
scaledDebt: bigint;
|
|
91
|
+
isBorrower: boolean;
|
|
92
|
+
isLiquidatable: boolean;
|
|
93
|
+
};
|
|
94
|
+
export type ReadPortfolioValue = {
|
|
95
|
+
user: Address;
|
|
96
|
+
portfolioValue: bigint;
|
|
97
|
+
};
|
|
98
|
+
export type ReadCoreGlobalDebt = {
|
|
99
|
+
totalScaledDebt: bigint;
|
|
100
|
+
};
|
|
101
|
+
export type ReadPositionLiquidationConfigOverride = {
|
|
102
|
+
positionId: bigint;
|
|
103
|
+
isSet: boolean;
|
|
104
|
+
maxLiquidationBonusBps: bigint;
|
|
105
|
+
liquidationFeeBps: bigint;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Cheap “badge” state useful for account lists and monitoring.
|
|
109
|
+
*/
|
|
110
|
+
export declare function readBorrowerState(params: {
|
|
111
|
+
core: {
|
|
112
|
+
read: {
|
|
113
|
+
getScaledDebt: (args: readonly [Address]) => Promise<bigint>;
|
|
114
|
+
isBorrower: (args: readonly [Address]) => Promise<boolean>;
|
|
115
|
+
isLiquidatable: (args: readonly [Address]) => Promise<boolean>;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
user: Address;
|
|
119
|
+
}): Promise<ReadBorrowerState>;
|
|
120
|
+
export declare function readPortfolioValue(params: {
|
|
121
|
+
core: {
|
|
122
|
+
read: {
|
|
123
|
+
getPortfolioValue: (args: readonly [Address]) => Promise<bigint>;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
user: Address;
|
|
127
|
+
}): Promise<ReadPortfolioValue>;
|
|
128
|
+
/**
|
|
129
|
+
* WARNING: can be large. Prefer `readBorrowersPage` for backends.
|
|
130
|
+
*/
|
|
131
|
+
export declare function readBorrowers(params: {
|
|
132
|
+
core: {
|
|
133
|
+
read: {
|
|
134
|
+
getBorrowers: () => Promise<readonly Address[]>;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
}): Promise<Address[]>;
|
|
138
|
+
export declare function readCoreGlobalDebt(params: {
|
|
139
|
+
core: {
|
|
140
|
+
read: {
|
|
141
|
+
totalScaledDebt: () => Promise<bigint>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}): Promise<ReadCoreGlobalDebt>;
|
|
145
|
+
export declare function readPositionLiquidationConfigOverride(params: {
|
|
146
|
+
core: {
|
|
147
|
+
read: {
|
|
148
|
+
getPositionLiquidationConfigOverride: (args: readonly [bigint]) => Promise<unknown>;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
positionId: bigint;
|
|
152
|
+
}): Promise<ReadPositionLiquidationConfigOverride>;
|
|
153
|
+
export declare function readPositionBalance(params: {
|
|
154
|
+
core: {
|
|
155
|
+
read: {
|
|
156
|
+
positionBalances: (args: readonly [Address, bigint]) => Promise<bigint>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
user: Address;
|
|
160
|
+
positionId: bigint;
|
|
161
|
+
}): Promise<{
|
|
162
|
+
user: Address;
|
|
163
|
+
positionId: bigint;
|
|
164
|
+
balance: bigint;
|
|
165
|
+
}>;
|
|
17
166
|
export declare function readAccountPositions(params: {
|
|
18
167
|
core: {
|
|
19
168
|
address: Address;
|
|
@@ -30,6 +179,48 @@ export declare function readAccountPositions(params: {
|
|
|
30
179
|
positionIds: bigint[];
|
|
31
180
|
balances: bigint[];
|
|
32
181
|
}>;
|
|
182
|
+
export type ReadBorrowersPage = {
|
|
183
|
+
total: number;
|
|
184
|
+
start: number;
|
|
185
|
+
end: number;
|
|
186
|
+
borrowers: Address[];
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Paged read of Core's `_borrowers` set.
|
|
190
|
+
*
|
|
191
|
+
* This is intended for monitoring/indexers; it avoids returning a massive array.
|
|
192
|
+
*/
|
|
193
|
+
export declare function readBorrowersPage(params: {
|
|
194
|
+
core: {
|
|
195
|
+
address: Address;
|
|
196
|
+
read: {
|
|
197
|
+
getBorrowersCount: () => Promise<bigint>;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
client: {
|
|
201
|
+
multicall: (args: any) => Promise<any>;
|
|
202
|
+
};
|
|
203
|
+
start: number;
|
|
204
|
+
limit: number;
|
|
205
|
+
chunkSize?: number;
|
|
206
|
+
}): Promise<ReadBorrowersPage>;
|
|
207
|
+
/**
|
|
208
|
+
* Hydrates a list of borrowers into normalized snapshots.
|
|
209
|
+
*
|
|
210
|
+
* Returns results aligned to input order.
|
|
211
|
+
*/
|
|
212
|
+
export declare function readManyAccountSnapshots(params: {
|
|
213
|
+
core: {
|
|
214
|
+
address: Address;
|
|
215
|
+
};
|
|
216
|
+
client: {
|
|
217
|
+
multicall: (args: any) => Promise<any>;
|
|
218
|
+
};
|
|
219
|
+
users: readonly Address[];
|
|
220
|
+
chunkSize?: number;
|
|
221
|
+
}): Promise<Array<{
|
|
222
|
+
user: Address;
|
|
223
|
+
} & ReadAccountSnapshot>>;
|
|
33
224
|
export type ReadHealthFactor = {
|
|
34
225
|
healthFactor: bigint;
|
|
35
226
|
canBeLiquidated: boolean;
|
|
@@ -180,4 +371,39 @@ export declare function readManyLiquidationBonusBps(params: {
|
|
|
180
371
|
healthFactors: readonly bigint[];
|
|
181
372
|
chunkSize?: number;
|
|
182
373
|
}): Promise<ReadManyLiquidationBonusBpsRow[]>;
|
|
374
|
+
export type ReadBorrowLimits = {
|
|
375
|
+
user: Address;
|
|
376
|
+
collateralValue: bigint;
|
|
377
|
+
debt: bigint;
|
|
378
|
+
maxBorrow: bigint;
|
|
379
|
+
healthFactor: bigint;
|
|
380
|
+
canBeLiquidated: boolean;
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* A small convenience bundle for frontends/backends.
|
|
384
|
+
*/
|
|
385
|
+
export declare function readBorrowLimits(params: {
|
|
386
|
+
core: {
|
|
387
|
+
read: {
|
|
388
|
+
getCollateralValue: (args: readonly [Address]) => Promise<bigint>;
|
|
389
|
+
getDebt: (args: readonly [Address]) => Promise<bigint>;
|
|
390
|
+
getMaxBorrow: (args: readonly [Address]) => Promise<bigint>;
|
|
391
|
+
getHealthFactor: (args: readonly [Address]) => Promise<unknown>;
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
user: Address;
|
|
395
|
+
}): Promise<ReadBorrowLimits>;
|
|
396
|
+
/**
|
|
397
|
+
* Multicall-chunked version of `readBorrowLimits`.
|
|
398
|
+
*/
|
|
399
|
+
export declare function readManyBorrowLimits(params: {
|
|
400
|
+
core: {
|
|
401
|
+
address: Address;
|
|
402
|
+
};
|
|
403
|
+
client: {
|
|
404
|
+
multicall: (args: any) => Promise<any>;
|
|
405
|
+
};
|
|
406
|
+
users: readonly Address[];
|
|
407
|
+
chunkSize?: number;
|
|
408
|
+
}): Promise<ReadBorrowLimits[]>;
|
|
183
409
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/views/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/views/core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,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AAE,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,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA8E9B"}
|
package/dist/views/core.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
2
|
import { multicallChunks } from "../batch.js";
|
|
3
3
|
import { abis } from "../generated.js";
|
|
4
|
+
// wraps: VarlaCore.getAccountSummary
|
|
4
5
|
export async function readAccountSnapshot(params) {
|
|
5
6
|
const raw = await params.core.read.getAccountSummary([params.user]);
|
|
6
7
|
// viem returns Solidity tuples as arrays (with optional named properties).
|
|
@@ -21,6 +22,118 @@ export async function readAccountSnapshot(params) {
|
|
|
21
22
|
}
|
|
22
23
|
return { portfolioValue, collateralValue, debt, healthFactor, maxBorrow };
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Read VarlaCore wiring + token metadata that most consumers need.
|
|
27
|
+
*/
|
|
28
|
+
// wraps: VarlaCore.collateralToken,VarlaCore.positionsToken,VarlaCore.pool,VarlaCore.oracle,VarlaCore.collateralDecimals
|
|
29
|
+
export async function readCoreAddresses(params) {
|
|
30
|
+
const [collateralToken, positionsToken, pool, oracle, collateralDecimalsRaw] = await Promise.all([
|
|
31
|
+
params.core.read.collateralToken(),
|
|
32
|
+
params.core.read.positionsToken(),
|
|
33
|
+
params.core.read.pool(),
|
|
34
|
+
params.core.read.oracle(),
|
|
35
|
+
params.core.read.collateralDecimals(),
|
|
36
|
+
]);
|
|
37
|
+
const collateralDecimals = typeof collateralDecimalsRaw === "bigint"
|
|
38
|
+
? Number(collateralDecimalsRaw)
|
|
39
|
+
: collateralDecimalsRaw;
|
|
40
|
+
if (!Number.isInteger(collateralDecimals) || collateralDecimals < 0) {
|
|
41
|
+
throw new Error(`Invalid collateralDecimals: ${String(collateralDecimalsRaw)}`);
|
|
42
|
+
}
|
|
43
|
+
return { collateralToken, positionsToken, pool, oracle, collateralDecimals };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Read max-positions safety bounds + current value (useful for deposit UX).
|
|
47
|
+
*/
|
|
48
|
+
// wraps: VarlaCore.maxPositions,VarlaCore.minMaxPositions,VarlaCore.maxMaxPositions
|
|
49
|
+
export async function readMaxPositionsConfig(params) {
|
|
50
|
+
const [maxPositions, minMaxPositions, maxMaxPositions] = await Promise.all([
|
|
51
|
+
params.core.read.maxPositions(),
|
|
52
|
+
params.core.read.minMaxPositions(),
|
|
53
|
+
params.core.read.maxMaxPositions(),
|
|
54
|
+
]);
|
|
55
|
+
return { maxPositions, minMaxPositions, maxMaxPositions };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Single-call alternative to `readAccountPositions` (no multicall).
|
|
59
|
+
*/
|
|
60
|
+
// wraps: VarlaCore.getPositions
|
|
61
|
+
export async function readAccountPositionsFull(params) {
|
|
62
|
+
const raw = await params.core.read.getPositions([params.user]);
|
|
63
|
+
const r = raw;
|
|
64
|
+
const positionIds = (r.positionIds ?? r[0]);
|
|
65
|
+
const balances = (r.balances ?? r[1]);
|
|
66
|
+
if (!Array.isArray(positionIds) || !Array.isArray(balances)) {
|
|
67
|
+
throw new Error("Unexpected getPositions() return shape");
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
user: params.user,
|
|
71
|
+
positionIds: positionIds,
|
|
72
|
+
balances: balances,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Efficiently hydrate balances for a known list of ids.
|
|
77
|
+
*/
|
|
78
|
+
// wraps: VarlaCore.getPositionBalances
|
|
79
|
+
export async function readPositionBalances(params) {
|
|
80
|
+
const balancesReadonly = await params.core.read.getPositionBalances([
|
|
81
|
+
params.user,
|
|
82
|
+
params.positionIds,
|
|
83
|
+
]);
|
|
84
|
+
const balances = [...balancesReadonly];
|
|
85
|
+
return { user: params.user, positionIds: [...params.positionIds], balances };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Cheap “badge” state useful for account lists and monitoring.
|
|
89
|
+
*/
|
|
90
|
+
// wraps: VarlaCore.getScaledDebt,VarlaCore.isBorrower,VarlaCore.isLiquidatable
|
|
91
|
+
export async function readBorrowerState(params) {
|
|
92
|
+
const [scaledDebt, isBorrower, isLiquidatable] = await Promise.all([
|
|
93
|
+
params.core.read.getScaledDebt([params.user]),
|
|
94
|
+
params.core.read.isBorrower([params.user]),
|
|
95
|
+
params.core.read.isLiquidatable([params.user]),
|
|
96
|
+
]);
|
|
97
|
+
return { user: params.user, scaledDebt, isBorrower, isLiquidatable };
|
|
98
|
+
}
|
|
99
|
+
// wraps: VarlaCore.getPortfolioValue
|
|
100
|
+
export async function readPortfolioValue(params) {
|
|
101
|
+
const portfolioValue = await params.core.read.getPortfolioValue([params.user]);
|
|
102
|
+
return { user: params.user, portfolioValue };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* WARNING: can be large. Prefer `readBorrowersPage` for backends.
|
|
106
|
+
*/
|
|
107
|
+
// wraps: VarlaCore.getBorrowers
|
|
108
|
+
export async function readBorrowers(params) {
|
|
109
|
+
const borrowers = await params.core.read.getBorrowers();
|
|
110
|
+
return [...borrowers];
|
|
111
|
+
}
|
|
112
|
+
// wraps: VarlaCore.totalScaledDebt
|
|
113
|
+
export async function readCoreGlobalDebt(params) {
|
|
114
|
+
const totalScaledDebt = await params.core.read.totalScaledDebt();
|
|
115
|
+
return { totalScaledDebt };
|
|
116
|
+
}
|
|
117
|
+
// wraps: VarlaCore.getPositionLiquidationConfigOverride
|
|
118
|
+
export async function readPositionLiquidationConfigOverride(params) {
|
|
119
|
+
const raw = await params.core.read.getPositionLiquidationConfigOverride([params.positionId]);
|
|
120
|
+
const r = raw;
|
|
121
|
+
const isSet = r.isSet ?? r[0];
|
|
122
|
+
const maxLiquidationBonusBps = r.maxLiquidationBonusBps ?? r[1];
|
|
123
|
+
const liquidationFeeBps = r.liquidationFeeBps ?? r[2];
|
|
124
|
+
if (typeof isSet !== "boolean" ||
|
|
125
|
+
typeof maxLiquidationBonusBps !== "bigint" ||
|
|
126
|
+
typeof liquidationFeeBps !== "bigint") {
|
|
127
|
+
throw new Error("Unexpected getPositionLiquidationConfigOverride() return shape");
|
|
128
|
+
}
|
|
129
|
+
return { positionId: params.positionId, isSet, maxLiquidationBonusBps, liquidationFeeBps };
|
|
130
|
+
}
|
|
131
|
+
// wraps: VarlaCore.positionBalances
|
|
132
|
+
export async function readPositionBalance(params) {
|
|
133
|
+
const balance = await params.core.read.positionBalances([params.user, params.positionId]);
|
|
134
|
+
return { user: params.user, positionId: params.positionId, balance };
|
|
135
|
+
}
|
|
136
|
+
// wraps: VarlaCore.getPositionIds,VarlaCore.getPositionBalance
|
|
24
137
|
export async function readAccountPositions(params) {
|
|
25
138
|
const { core, client, user } = params;
|
|
26
139
|
const chunkSize = params.chunkSize ?? 256;
|
|
@@ -48,11 +161,98 @@ export async function readAccountPositions(params) {
|
|
|
48
161
|
}
|
|
49
162
|
return { positionIds, balances };
|
|
50
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Paged read of Core's `_borrowers` set.
|
|
166
|
+
*
|
|
167
|
+
* This is intended for monitoring/indexers; it avoids returning a massive array.
|
|
168
|
+
*/
|
|
169
|
+
// wraps: VarlaCore.getBorrowersCount,VarlaCore.getBorrowerAt
|
|
170
|
+
export async function readBorrowersPage(params) {
|
|
171
|
+
const chunkSize = params.chunkSize ?? 256;
|
|
172
|
+
if (!Number.isInteger(params.start) || params.start < 0) {
|
|
173
|
+
throw new Error(`Invalid start: ${params.start}`);
|
|
174
|
+
}
|
|
175
|
+
if (!Number.isInteger(params.limit) || params.limit <= 0) {
|
|
176
|
+
throw new Error(`Invalid limit: ${params.limit}`);
|
|
177
|
+
}
|
|
178
|
+
const count = await params.core.read.getBorrowersCount();
|
|
179
|
+
const total = Number(count);
|
|
180
|
+
if (!Number.isSafeInteger(total) || total < 0) {
|
|
181
|
+
throw new Error(`Invalid borrowers count: ${count}`);
|
|
182
|
+
}
|
|
183
|
+
const start = Math.min(params.start, total);
|
|
184
|
+
const end = Math.min(total, start + params.limit);
|
|
185
|
+
if (end <= start) {
|
|
186
|
+
return { total, start, end, borrowers: [] };
|
|
187
|
+
}
|
|
188
|
+
const calls = Array.from({ length: end - start }, (_, j) => {
|
|
189
|
+
const i = start + j;
|
|
190
|
+
return {
|
|
191
|
+
address: params.core.address,
|
|
192
|
+
abi: abis.VARLACORE_ABI,
|
|
193
|
+
functionName: "getBorrowerAt",
|
|
194
|
+
args: [BigInt(i)],
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
const res = await multicallChunks({
|
|
198
|
+
client: params.client,
|
|
199
|
+
contracts: calls,
|
|
200
|
+
chunkSize,
|
|
201
|
+
});
|
|
202
|
+
const borrowers = [];
|
|
203
|
+
for (const r of res) {
|
|
204
|
+
if (r.status !== "success") {
|
|
205
|
+
throw new Error(`Core getBorrowerAt multicall failed: ${String(r.error ?? "unknown")}`);
|
|
206
|
+
}
|
|
207
|
+
borrowers.push(r.result);
|
|
208
|
+
}
|
|
209
|
+
return { total, start, end, borrowers };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Hydrates a list of borrowers into normalized snapshots.
|
|
213
|
+
*
|
|
214
|
+
* Returns results aligned to input order.
|
|
215
|
+
*/
|
|
216
|
+
// wraps: VarlaCore.getAccountSummary
|
|
217
|
+
export async function readManyAccountSnapshots(params) {
|
|
218
|
+
const chunkSize = params.chunkSize ?? 256;
|
|
219
|
+
if (params.users.length === 0)
|
|
220
|
+
return [];
|
|
221
|
+
const calls = params.users.map((user) => ({
|
|
222
|
+
address: params.core.address,
|
|
223
|
+
abi: abis.VARLACORE_ABI,
|
|
224
|
+
functionName: "getAccountSummary",
|
|
225
|
+
args: [user],
|
|
226
|
+
}));
|
|
227
|
+
const res = await multicallChunks({
|
|
228
|
+
client: params.client,
|
|
229
|
+
contracts: calls,
|
|
230
|
+
chunkSize,
|
|
231
|
+
});
|
|
232
|
+
const out = [];
|
|
233
|
+
for (let i = 0; i < res.length; i++) {
|
|
234
|
+
const r = res[i];
|
|
235
|
+
if (r.status !== "success") {
|
|
236
|
+
throw new Error(`Core getAccountSummary multicall failed: ${String(r.error ?? "unknown")}`);
|
|
237
|
+
}
|
|
238
|
+
const snap = await readAccountSnapshot({
|
|
239
|
+
core: {
|
|
240
|
+
read: {
|
|
241
|
+
getAccountSummary: async () => r.result,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
user: params.users[i],
|
|
245
|
+
});
|
|
246
|
+
out.push({ user: params.users[i], ...snap });
|
|
247
|
+
}
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
51
250
|
/**
|
|
52
251
|
* Read the user's health factor and whether liquidation is currently allowed.
|
|
53
252
|
*
|
|
54
253
|
* Normalizes `VarlaCore.getHealthFactor(user)` tuple return.
|
|
55
254
|
*/
|
|
255
|
+
// wraps: VarlaCore.getHealthFactor
|
|
56
256
|
export async function readHealthFactor(params) {
|
|
57
257
|
const raw = await params.core.read.getHealthFactor([params.user]);
|
|
58
258
|
const r = raw;
|
|
@@ -66,6 +266,7 @@ export async function readHealthFactor(params) {
|
|
|
66
266
|
/**
|
|
67
267
|
* Normalized wrapper over `VarlaCore.getLiquidationConfig()`.
|
|
68
268
|
*/
|
|
269
|
+
// wraps: VarlaCore.getLiquidationConfig
|
|
69
270
|
export async function readLiquidationConfig(params) {
|
|
70
271
|
const raw = await params.core.read.getLiquidationConfig();
|
|
71
272
|
const r = raw;
|
|
@@ -92,6 +293,7 @@ export async function readLiquidationConfig(params) {
|
|
|
92
293
|
/**
|
|
93
294
|
* Normalized wrapper over `VarlaCore.getDefaultLtvConfig()`.
|
|
94
295
|
*/
|
|
296
|
+
// wraps: VarlaCore.getDefaultLtvConfig
|
|
95
297
|
export async function readDefaultLtvConfig(params) {
|
|
96
298
|
const raw = await params.core.read.getDefaultLtvConfig();
|
|
97
299
|
const r = raw;
|
|
@@ -108,6 +310,7 @@ export async function readDefaultLtvConfig(params) {
|
|
|
108
310
|
/**
|
|
109
311
|
* Normalized wrapper over `VarlaCore.getTierLiquidationConfig(tier)`.
|
|
110
312
|
*/
|
|
313
|
+
// wraps: VarlaCore.getTierLiquidationConfig
|
|
111
314
|
export async function readTierLiquidationConfig(params) {
|
|
112
315
|
const raw = await params.core.read.getTierLiquidationConfig([params.tier]);
|
|
113
316
|
const r = raw;
|
|
@@ -121,6 +324,7 @@ export async function readTierLiquidationConfig(params) {
|
|
|
121
324
|
/**
|
|
122
325
|
* Normalized wrapper over `VarlaCore.getLiquidationParamsForPosition(positionId)`.
|
|
123
326
|
*/
|
|
327
|
+
// wraps: VarlaCore.getLiquidationParamsForPosition
|
|
124
328
|
export async function readLiquidationParamsForPosition(params) {
|
|
125
329
|
const raw = await params.core.read.getLiquidationParamsForPosition([params.positionId]);
|
|
126
330
|
const r = raw;
|
|
@@ -134,6 +338,7 @@ export async function readLiquidationParamsForPosition(params) {
|
|
|
134
338
|
/**
|
|
135
339
|
* Normalized wrapper over `VarlaCore.getPositionLtvOverride(positionId)`.
|
|
136
340
|
*/
|
|
341
|
+
// wraps: VarlaCore.getPositionLtvOverride
|
|
137
342
|
export async function readPositionLtvOverride(params) {
|
|
138
343
|
const raw = await params.core.read.getPositionLtvOverride([params.positionId]);
|
|
139
344
|
const r = raw;
|
|
@@ -149,6 +354,7 @@ export async function readPositionLtvOverride(params) {
|
|
|
149
354
|
*
|
|
150
355
|
* This is the *effective* LTV for the position (includes early-closure factor and overrides).
|
|
151
356
|
*/
|
|
357
|
+
// wraps: VarlaCore.getLtvForPosition
|
|
152
358
|
export async function readLtvForPosition(params) {
|
|
153
359
|
const ltvWad = await params.core.read.getLtvForPosition([params.positionId]);
|
|
154
360
|
return { positionId: params.positionId, ltvWad };
|
|
@@ -156,6 +362,7 @@ export async function readLtvForPosition(params) {
|
|
|
156
362
|
/**
|
|
157
363
|
* Thin wrapper over `VarlaCore.getLiquidationBonusBps(positionId, healthFactor)`.
|
|
158
364
|
*/
|
|
365
|
+
// wraps: VarlaCore.getLiquidationBonusBps
|
|
159
366
|
export async function readLiquidationBonusBps(params) {
|
|
160
367
|
const bonusBps = await params.core.read.getLiquidationBonusBps([
|
|
161
368
|
params.positionId,
|
|
@@ -168,6 +375,7 @@ export async function readLiquidationBonusBps(params) {
|
|
|
168
375
|
*
|
|
169
376
|
* Useful for UIs that need to visualize liquidation incentive curves.
|
|
170
377
|
*/
|
|
378
|
+
// wraps: VarlaCore.getLiquidationBonusBps
|
|
171
379
|
export async function readManyLiquidationBonusBps(params) {
|
|
172
380
|
const chunkSize = params.chunkSize ?? 256;
|
|
173
381
|
if (params.positionIds.length === 0)
|
|
@@ -204,3 +412,99 @@ export async function readManyLiquidationBonusBps(params) {
|
|
|
204
412
|
}
|
|
205
413
|
return out;
|
|
206
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* A small convenience bundle for frontends/backends.
|
|
417
|
+
*/
|
|
418
|
+
// wraps: VarlaCore.getCollateralValue,VarlaCore.getDebt,VarlaCore.getMaxBorrow,VarlaCore.getHealthFactor
|
|
419
|
+
export async function readBorrowLimits(params) {
|
|
420
|
+
const [collateralValue, debt, maxBorrow, hf] = await Promise.all([
|
|
421
|
+
params.core.read.getCollateralValue([params.user]),
|
|
422
|
+
params.core.read.getDebt([params.user]),
|
|
423
|
+
params.core.read.getMaxBorrow([params.user]),
|
|
424
|
+
readHealthFactor({ core: params.core, user: params.user }),
|
|
425
|
+
]);
|
|
426
|
+
return {
|
|
427
|
+
user: params.user,
|
|
428
|
+
collateralValue,
|
|
429
|
+
debt,
|
|
430
|
+
maxBorrow,
|
|
431
|
+
healthFactor: hf.healthFactor,
|
|
432
|
+
canBeLiquidated: hf.canBeLiquidated,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Multicall-chunked version of `readBorrowLimits`.
|
|
437
|
+
*/
|
|
438
|
+
// wraps: VarlaCore.getCollateralValue,VarlaCore.getDebt,VarlaCore.getMaxBorrow,VarlaCore.getHealthFactor
|
|
439
|
+
export async function readManyBorrowLimits(params) {
|
|
440
|
+
const chunkSize = params.chunkSize ?? 256;
|
|
441
|
+
if (params.users.length === 0)
|
|
442
|
+
return [];
|
|
443
|
+
const calls = params.users.flatMap((user) => [
|
|
444
|
+
{
|
|
445
|
+
address: params.core.address,
|
|
446
|
+
abi: abis.VARLACORE_ABI,
|
|
447
|
+
functionName: "getCollateralValue",
|
|
448
|
+
args: [user],
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
address: params.core.address,
|
|
452
|
+
abi: abis.VARLACORE_ABI,
|
|
453
|
+
functionName: "getDebt",
|
|
454
|
+
args: [user],
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
address: params.core.address,
|
|
458
|
+
abi: abis.VARLACORE_ABI,
|
|
459
|
+
functionName: "getMaxBorrow",
|
|
460
|
+
args: [user],
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
address: params.core.address,
|
|
464
|
+
abi: abis.VARLACORE_ABI,
|
|
465
|
+
functionName: "getHealthFactor",
|
|
466
|
+
args: [user],
|
|
467
|
+
},
|
|
468
|
+
]);
|
|
469
|
+
const res = await multicallChunks({
|
|
470
|
+
client: params.client,
|
|
471
|
+
contracts: calls,
|
|
472
|
+
chunkSize,
|
|
473
|
+
});
|
|
474
|
+
const out = [];
|
|
475
|
+
const stride = 4;
|
|
476
|
+
for (let i = 0; i < params.users.length; i++) {
|
|
477
|
+
const base = i * stride;
|
|
478
|
+
const r0 = res[base + 0];
|
|
479
|
+
const r1 = res[base + 1];
|
|
480
|
+
const r2 = res[base + 2];
|
|
481
|
+
const r3 = res[base + 3];
|
|
482
|
+
if (r0.status !== "success") {
|
|
483
|
+
throw new Error(`Core getCollateralValue multicall failed: ${String(r0.error ?? "unknown")}`);
|
|
484
|
+
}
|
|
485
|
+
if (r1.status !== "success") {
|
|
486
|
+
throw new Error(`Core getDebt multicall failed: ${String(r1.error ?? "unknown")}`);
|
|
487
|
+
}
|
|
488
|
+
if (r2.status !== "success") {
|
|
489
|
+
throw new Error(`Core getMaxBorrow multicall failed: ${String(r2.error ?? "unknown")}`);
|
|
490
|
+
}
|
|
491
|
+
if (r3.status !== "success") {
|
|
492
|
+
throw new Error(`Core getHealthFactor multicall failed: ${String(r3.error ?? "unknown")}`);
|
|
493
|
+
}
|
|
494
|
+
const hfRaw = r3.result;
|
|
495
|
+
const healthFactor = hfRaw.healthFactor ?? hfRaw[0];
|
|
496
|
+
const canBeLiquidated = hfRaw.canBeLiquidated ?? hfRaw[1];
|
|
497
|
+
if (typeof healthFactor !== "bigint" || typeof canBeLiquidated !== "boolean") {
|
|
498
|
+
throw new Error("Unexpected getHealthFactor() return shape");
|
|
499
|
+
}
|
|
500
|
+
out.push({
|
|
501
|
+
user: params.users[i],
|
|
502
|
+
collateralValue: r0.result,
|
|
503
|
+
debt: r1.result,
|
|
504
|
+
maxBorrow: r2.result,
|
|
505
|
+
healthFactor,
|
|
506
|
+
canBeLiquidated,
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
return out;
|
|
510
|
+
}
|
package/dist/views/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/views/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/views/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
package/dist/views/index.js
CHANGED