@varla/sdk 2.16.0 → 2.18.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/AGENTS.md +7 -7
- package/CHANGELOG.md +33 -0
- package/dist/addresses/polygon.js +12 -12
- package/dist/addresses/polygonProxy.js +12 -12
- package/dist/views/core.d.ts +24 -0
- package/dist/views/core.d.ts.map +1 -1
- package/dist/views/core.js +135 -0
- package/dist/views/core.js.map +1 -1
- package/dist/views/liquidators.d.ts +26 -0
- package/dist/views/liquidators.d.ts.map +1 -1
- package/dist/views/liquidators.js +80 -14
- package/dist/views/liquidators.js.map +1 -1
- package/dist/views/oracle.d.ts +106 -0
- package/dist/views/oracle.d.ts.map +1 -1
- package/dist/views/oracle.js +305 -1
- package/dist/views/oracle.js.map +1 -1
- package/dist/views/pool.d.ts +24 -0
- package/dist/views/pool.d.ts.map +1 -1
- package/dist/views/pool.js +127 -0
- package/dist/views/pool.js.map +1 -1
- package/dist/views/system.d.ts +20 -1
- package/dist/views/system.d.ts.map +1 -1
- package/dist/views/system.js +32 -2
- package/dist/views/system.js.map +1 -1
- package/package.json +1 -1
- package/src/addresses/polygon.json +10 -10
- package/src/addresses/polygon.ts +12 -12
- package/src/addresses/polygonProxy.ts +12 -12
- package/src/views/core.ts +161 -0
- package/src/views/liquidators.ts +104 -21
- package/src/views/oracle.ts +388 -1
- package/src/views/pool.ts +153 -0
- package/src/views/system.ts +51 -3
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/views/system.ts"],"names":[],"mappings":"AAEA,O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1
|
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
-
import { readDefaultLtvConfig, readLiquidationConfig } from "./core.js";
|
|
2
|
+
import { readCoreDashboard, readDefaultLtvConfig, readLiquidationConfig } from "./core.js";
|
|
3
3
|
import { readOracleConfig } from "./oracle.js";
|
|
4
|
-
import { readPoolAccounting, readPoolCaps, readPoolSnapshot } from "./pool.js";
|
|
4
|
+
import { readPoolAccounting, readPoolCaps, readPoolDashboard, readPoolSnapshot } from "./pool.js";
|
|
5
5
|
/**
|
|
6
6
|
* A lightweight “global protocol state” read for dashboards.
|
|
7
7
|
*
|
|
@@ -21,4 +21,34 @@ export async function readSystemSnapshot(params) {
|
|
|
21
21
|
]);
|
|
22
22
|
return { pool, poolCaps, poolAccounting, coreLtv, coreLiquidation, oracle };
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Multicall-backed system snapshot used by dashboards.
|
|
26
|
+
*/
|
|
27
|
+
export async function readSystemDashboardSnapshot(params) {
|
|
28
|
+
const [poolDashboard, coreDashboard, oracle] = await Promise.all([
|
|
29
|
+
readPoolDashboard({
|
|
30
|
+
pool: { address: params.pool.address },
|
|
31
|
+
client: params.client,
|
|
32
|
+
}),
|
|
33
|
+
readCoreDashboard({
|
|
34
|
+
core: { address: params.core.address },
|
|
35
|
+
client: params.client,
|
|
36
|
+
}),
|
|
37
|
+
readOracleConfig({ oracle: params.oracle }),
|
|
38
|
+
]);
|
|
39
|
+
return {
|
|
40
|
+
pool: poolDashboard.snapshot,
|
|
41
|
+
poolCaps: poolDashboard.caps,
|
|
42
|
+
poolAccounting: poolDashboard.accounting,
|
|
43
|
+
coreLtv: {
|
|
44
|
+
conservative: coreDashboard.ltvConfig.tier0,
|
|
45
|
+
moderate: coreDashboard.ltvConfig.tier1,
|
|
46
|
+
risk: coreDashboard.ltvConfig.tier2,
|
|
47
|
+
},
|
|
48
|
+
coreLiquidation: coreDashboard.liqConfig,
|
|
49
|
+
oracle,
|
|
50
|
+
poolSharePrice: poolDashboard.sharePrice,
|
|
51
|
+
poolHealthScore: poolDashboard.healthScore,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
24
54
|
//# sourceMappingURL=system.js.map
|
package/dist/views/system.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../src/views/system.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAGpE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;
|
|
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,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,gBAAgB,CAAC,EAAE,MAAM,EAAE,MAAM,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
6
|
-
"VarlaAccessManager": "
|
|
7
|
-
"VarlaOracle": "
|
|
8
|
-
"VarlaCore": "
|
|
9
|
-
"VarlaPool": "
|
|
10
|
-
"OracleUpdaterRouter": "
|
|
11
|
-
"VarlaLiquidator": "
|
|
12
|
-
"VarlaMergeLiquidator": "
|
|
13
|
-
"VarlaConvertLiquidator": "
|
|
14
|
-
"PolymarketCtfAdapter": "
|
|
15
|
-
"PolymarketNegRiskMergeAdapter": "
|
|
6
|
+
"VarlaAccessManager": "0xF5Acd8496248bb911fd1dE37f12F27Ae2D4EE973",
|
|
7
|
+
"VarlaOracle": "0x93275d07182EF45E79Ac976Ab3b8b8eD8E50966e",
|
|
8
|
+
"VarlaCore": "0xBCF248890AC7BE6A54b8E94775C3fD59Cf689340",
|
|
9
|
+
"VarlaPool": "0xB1820B7F807853a03a6a76a5694622F499F71428",
|
|
10
|
+
"OracleUpdaterRouter": "0x67c30c998d549be0efcaAE01623720BB081fC702",
|
|
11
|
+
"VarlaLiquidator": "0xa1d30AEC3106bfe10311D290228F342727Cae5cF",
|
|
12
|
+
"VarlaMergeLiquidator": "0xDa929503D720653433eb9DB273E5a42d8C14aF90",
|
|
13
|
+
"VarlaConvertLiquidator": "0xA59e346f4C663AF4cF9B3F302B3eAd460101d709",
|
|
14
|
+
"PolymarketCtfAdapter": "0x1715CC1c9797098F77993d6aa0D190F323aa9421",
|
|
15
|
+
"PolymarketNegRiskMergeAdapter": "0x3611E0AA36ebEFe3b555Db9b5BDcB071Fb64a477"
|
|
16
16
|
}
|
|
17
17
|
}
|
package/src/addresses/polygon.ts
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import type { AddressBook } from "../types";
|
|
3
3
|
|
|
4
4
|
export const polygon: AddressBook = {
|
|
5
|
-
accessManager: "
|
|
6
|
-
oracle: "
|
|
7
|
-
core: "
|
|
8
|
-
pool: "
|
|
9
|
-
oracleUpdaterRouter: "
|
|
10
|
-
interestRateStrategy: "
|
|
11
|
-
proxyAdmin: "
|
|
12
|
-
liquidator: "
|
|
13
|
-
mergeLiquidator: "
|
|
14
|
-
convertLiquidator: "
|
|
15
|
-
polymarketCtfAdapter: "
|
|
16
|
-
negRiskMergeAdapter: "
|
|
5
|
+
accessManager: "0xF5Acd8496248bb911fd1dE37f12F27Ae2D4EE973",
|
|
6
|
+
oracle: "0x93275d07182EF45E79Ac976Ab3b8b8eD8E50966e",
|
|
7
|
+
core: "0xBCF248890AC7BE6A54b8E94775C3fD59Cf689340",
|
|
8
|
+
pool: "0xB1820B7F807853a03a6a76a5694622F499F71428",
|
|
9
|
+
oracleUpdaterRouter: "0x67c30c998d549be0efcaAE01623720BB081fC702",
|
|
10
|
+
interestRateStrategy: "0x4c728684f72A232a125ABCC726A5b94768815efE",
|
|
11
|
+
proxyAdmin: "0xEB21e1513F0b522A78d8b8285094e89563e164C6",
|
|
12
|
+
liquidator: "0xa1d30AEC3106bfe10311D290228F342727Cae5cF",
|
|
13
|
+
mergeLiquidator: "0xDa929503D720653433eb9DB273E5a42d8C14aF90",
|
|
14
|
+
convertLiquidator: "0xA59e346f4C663AF4cF9B3F302B3eAd460101d709",
|
|
15
|
+
polymarketCtfAdapter: "0x1715CC1c9797098F77993d6aa0D190F323aa9421",
|
|
16
|
+
negRiskMergeAdapter: "0x3611E0AA36ebEFe3b555Db9b5BDcB071Fb64a477",
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import type { AddressBook } from "../types";
|
|
3
3
|
|
|
4
4
|
export const polygonProxy: AddressBook = {
|
|
5
|
-
accessManager: "
|
|
6
|
-
oracle: "
|
|
7
|
-
core: "
|
|
8
|
-
pool: "
|
|
9
|
-
oracleUpdaterRouter: "
|
|
10
|
-
interestRateStrategy: "
|
|
11
|
-
proxyAdmin: "
|
|
12
|
-
liquidator: "
|
|
13
|
-
mergeLiquidator: "
|
|
14
|
-
convertLiquidator: "
|
|
15
|
-
polymarketCtfAdapter: "
|
|
16
|
-
negRiskMergeAdapter: "
|
|
5
|
+
accessManager: "0xF5Acd8496248bb911fd1dE37f12F27Ae2D4EE973",
|
|
6
|
+
oracle: "0xf507345D044D29DE9696c9fce02E9202cB902107",
|
|
7
|
+
core: "0x760453D0380222AaFB959145c20C9B32EBb1B636",
|
|
8
|
+
pool: "0x0fe32e729aE12600Ec8CbE6950456171C98120AE",
|
|
9
|
+
oracleUpdaterRouter: "0x67c30c998d549be0efcaAE01623720BB081fC702",
|
|
10
|
+
interestRateStrategy: "0xf3aac20247fd73ae5C8ACFA0Cf25cfC463332E82",
|
|
11
|
+
proxyAdmin: "0xEB21e1513F0b522A78d8b8285094e89563e164C6",
|
|
12
|
+
liquidator: "0x76B21eFF6F232CB9b647007A5E505a5392C7417F",
|
|
13
|
+
mergeLiquidator: "0xd0017264cd4Ee870F6869F1ab47f6ff579c31ba5",
|
|
14
|
+
convertLiquidator: "0x68421cDD230e550ac467Ae980454032bf8CE3651",
|
|
15
|
+
polymarketCtfAdapter: "0x1715CC1c9797098F77993d6aa0D190F323aa9421",
|
|
16
|
+
negRiskMergeAdapter: "0x3611E0AA36ebEFe3b555Db9b5BDcB071Fb64a477",
|
|
17
17
|
};
|
|
18
18
|
|
package/src/views/core.ts
CHANGED
|
@@ -891,6 +891,19 @@ export type ReadTierLiquidationConfig = {
|
|
|
891
891
|
liquidationFeeBps: bigint;
|
|
892
892
|
};
|
|
893
893
|
|
|
894
|
+
export type ReadCoreDashboard = {
|
|
895
|
+
globalDebt: ReadCoreGlobalDebt;
|
|
896
|
+
coreAddresses: ReadCoreAddresses;
|
|
897
|
+
maxPositions: ReadMaxPositionsConfig;
|
|
898
|
+
ltvConfig: ReadTieredLtvConfig;
|
|
899
|
+
liqConfig: ReadLiquidationConfig;
|
|
900
|
+
tierLiq: readonly [
|
|
901
|
+
ReadTierLiquidationConfig | null,
|
|
902
|
+
ReadTierLiquidationConfig | null,
|
|
903
|
+
ReadTierLiquidationConfig | null,
|
|
904
|
+
];
|
|
905
|
+
};
|
|
906
|
+
|
|
894
907
|
/**
|
|
895
908
|
* Normalized wrapper over `VarlaCore.getTierLiquidationConfig(tier)`.
|
|
896
909
|
*/
|
|
@@ -915,6 +928,154 @@ export async function readTierLiquidationConfig(params: {
|
|
|
915
928
|
return { tier: params.tier, maxLiquidationBonusBps, liquidationFeeBps };
|
|
916
929
|
}
|
|
917
930
|
|
|
931
|
+
/**
|
|
932
|
+
* Multicall-backed aggregate reader for the admin Core page.
|
|
933
|
+
*/
|
|
934
|
+
// wraps: VarlaCore.totalScaledDebt,VarlaCore.collateralToken,VarlaCore.positionsToken,VarlaCore.pool,VarlaCore.oracle,VarlaCore.collateralDecimals,VarlaCore.maxPositions,VarlaCore.minMaxPositions,VarlaCore.maxMaxPositions,VarlaCore.getDefaultLtvConfig,VarlaCore.getLiquidationConfig,VarlaCore.getTierLiquidationConfig
|
|
935
|
+
export async function readCoreDashboard(params: {
|
|
936
|
+
core: { address: Address };
|
|
937
|
+
client: { multicall: (args: any) => Promise<any> };
|
|
938
|
+
chunkSize?: number;
|
|
939
|
+
}): Promise<ReadCoreDashboard> {
|
|
940
|
+
const chunkSize = params.chunkSize ?? 256;
|
|
941
|
+
|
|
942
|
+
const calls = [
|
|
943
|
+
{
|
|
944
|
+
address: params.core.address,
|
|
945
|
+
abi: abis.VARLACORE_ABI,
|
|
946
|
+
functionName: "totalScaledDebt" as const,
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
address: params.core.address,
|
|
950
|
+
abi: abis.VARLACORE_ABI,
|
|
951
|
+
functionName: "collateralToken" as const,
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
address: params.core.address,
|
|
955
|
+
abi: abis.VARLACORE_ABI,
|
|
956
|
+
functionName: "positionsToken" as const,
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
address: params.core.address,
|
|
960
|
+
abi: abis.VARLACORE_ABI,
|
|
961
|
+
functionName: "pool" as const,
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
address: params.core.address,
|
|
965
|
+
abi: abis.VARLACORE_ABI,
|
|
966
|
+
functionName: "oracle" as const,
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
address: params.core.address,
|
|
970
|
+
abi: abis.VARLACORE_ABI,
|
|
971
|
+
functionName: "collateralDecimals" as const,
|
|
972
|
+
},
|
|
973
|
+
{
|
|
974
|
+
address: params.core.address,
|
|
975
|
+
abi: abis.VARLACORE_ABI,
|
|
976
|
+
functionName: "maxPositions" as const,
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
address: params.core.address,
|
|
980
|
+
abi: abis.VARLACORE_ABI,
|
|
981
|
+
functionName: "minMaxPositions" as const,
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
address: params.core.address,
|
|
985
|
+
abi: abis.VARLACORE_ABI,
|
|
986
|
+
functionName: "maxMaxPositions" as const,
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
address: params.core.address,
|
|
990
|
+
abi: abis.VARLACORE_ABI,
|
|
991
|
+
functionName: "getDefaultLtvConfig" as const,
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
address: params.core.address,
|
|
995
|
+
abi: abis.VARLACORE_ABI,
|
|
996
|
+
functionName: "getLiquidationConfig" as const,
|
|
997
|
+
},
|
|
998
|
+
{
|
|
999
|
+
address: params.core.address,
|
|
1000
|
+
abi: abis.VARLACORE_ABI,
|
|
1001
|
+
functionName: "getTierLiquidationConfig" as const,
|
|
1002
|
+
args: [0] as const,
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
address: params.core.address,
|
|
1006
|
+
abi: abis.VARLACORE_ABI,
|
|
1007
|
+
functionName: "getTierLiquidationConfig" as const,
|
|
1008
|
+
args: [1] as const,
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
address: params.core.address,
|
|
1012
|
+
abi: abis.VARLACORE_ABI,
|
|
1013
|
+
functionName: "getTierLiquidationConfig" as const,
|
|
1014
|
+
args: [2] as const,
|
|
1015
|
+
},
|
|
1016
|
+
];
|
|
1017
|
+
|
|
1018
|
+
const res = await multicallChunks({
|
|
1019
|
+
client: params.client as any,
|
|
1020
|
+
contracts: calls as any,
|
|
1021
|
+
chunkSize,
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
const ensureSuccess = (r: any, label: string) => {
|
|
1025
|
+
if (r.status !== "success") {
|
|
1026
|
+
throw new Error(`Core dashboard ${label} multicall failed: ${String(r.error ?? "unknown")}`);
|
|
1027
|
+
}
|
|
1028
|
+
return r.result;
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
const totalScaledDebt = ensureSuccess((res as any[])[0], "totalScaledDebt") as bigint;
|
|
1032
|
+
const collateralToken = ensureSuccess((res as any[])[1], "collateralToken") as Address;
|
|
1033
|
+
const positionsToken = ensureSuccess((res as any[])[2], "positionsToken") as Address;
|
|
1034
|
+
const pool = ensureSuccess((res as any[])[3], "pool") as Address;
|
|
1035
|
+
const oracle = ensureSuccess((res as any[])[4], "oracle") as Address;
|
|
1036
|
+
const collateralDecimalsRaw = ensureSuccess((res as any[])[5], "collateralDecimals") as
|
|
1037
|
+
| bigint
|
|
1038
|
+
| number;
|
|
1039
|
+
const maxPositions = ensureSuccess((res as any[])[6], "maxPositions") as bigint;
|
|
1040
|
+
const minMaxPositions = ensureSuccess((res as any[])[7], "minMaxPositions") as bigint;
|
|
1041
|
+
const maxMaxPositions = ensureSuccess((res as any[])[8], "maxMaxPositions") as bigint;
|
|
1042
|
+
const defaultLtvRaw = ensureSuccess((res as any[])[9], "getDefaultLtvConfig");
|
|
1043
|
+
const liqRaw = ensureSuccess((res as any[])[10], "getLiquidationConfig");
|
|
1044
|
+
const tier0Raw = ensureSuccess((res as any[])[11], "getTierLiquidationConfig(0)");
|
|
1045
|
+
const tier1Raw = ensureSuccess((res as any[])[12], "getTierLiquidationConfig(1)");
|
|
1046
|
+
const tier2Raw = ensureSuccess((res as any[])[13], "getTierLiquidationConfig(2)");
|
|
1047
|
+
|
|
1048
|
+
const coreLike = {
|
|
1049
|
+
read: {
|
|
1050
|
+
getDefaultLtvConfig: async () => defaultLtvRaw,
|
|
1051
|
+
getLiquidationConfig: async () => liqRaw,
|
|
1052
|
+
getTierLiquidationConfig: async (args: readonly [number]) => {
|
|
1053
|
+
if (args[0] === 0) return tier0Raw;
|
|
1054
|
+
if (args[0] === 1) return tier1Raw;
|
|
1055
|
+
return tier2Raw;
|
|
1056
|
+
},
|
|
1057
|
+
},
|
|
1058
|
+
} as any;
|
|
1059
|
+
|
|
1060
|
+
const collateralDecimals =
|
|
1061
|
+
typeof collateralDecimalsRaw === "bigint"
|
|
1062
|
+
? Number(collateralDecimalsRaw)
|
|
1063
|
+
: collateralDecimalsRaw;
|
|
1064
|
+
|
|
1065
|
+
return {
|
|
1066
|
+
globalDebt: { totalScaledDebt },
|
|
1067
|
+
coreAddresses: { collateralToken, positionsToken, pool, oracle, collateralDecimals },
|
|
1068
|
+
maxPositions: { maxPositions, minMaxPositions, maxMaxPositions },
|
|
1069
|
+
ltvConfig: await readTieredLtvConfig({ core: coreLike }),
|
|
1070
|
+
liqConfig: await readLiquidationConfig({ core: coreLike }),
|
|
1071
|
+
tierLiq: [
|
|
1072
|
+
await readTierLiquidationConfig({ core: coreLike, tier: 0 }),
|
|
1073
|
+
await readTierLiquidationConfig({ core: coreLike, tier: 1 }),
|
|
1074
|
+
await readTierLiquidationConfig({ core: coreLike, tier: 2 }),
|
|
1075
|
+
] as const,
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
|
|
918
1079
|
export type ReadLiquidationParamsForPosition = {
|
|
919
1080
|
positionId: bigint;
|
|
920
1081
|
maxLiquidationBonusBps: bigint;
|
package/src/views/liquidators.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Address, PublicClient } from "viem";
|
|
4
4
|
|
|
5
|
+
import { multicallChunks } from "../batch.js";
|
|
6
|
+
import { abis } from "../generated.js";
|
|
5
7
|
import { readAccountPositionsFull } from "./core.js";
|
|
6
8
|
import { type ReadPositionSnapshot, readManyPositionSnapshots } from "./oracle.js";
|
|
7
9
|
|
|
@@ -51,17 +53,8 @@ export type ReadCanLiquidate = {
|
|
|
51
53
|
currentBonus: bigint;
|
|
52
54
|
};
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
* Normalized wrapper over `*.canLiquidate(user)`.
|
|
56
|
-
*/
|
|
57
|
-
// wraps: VarlaLiquidator.canLiquidate,VarlaMergeLiquidator.canLiquidate,VarlaConvertLiquidator.canLiquidate
|
|
58
|
-
export async function readCanLiquidate(params: {
|
|
59
|
-
liquidator: CanLiquidateLike;
|
|
60
|
-
user: Address;
|
|
61
|
-
}): Promise<ReadCanLiquidate> {
|
|
62
|
-
const raw = await params.liquidator.read.canLiquidate([params.user]);
|
|
56
|
+
function normalizeCanLiquidate(raw: unknown, user: Address): ReadCanLiquidate {
|
|
63
57
|
const r: any = raw as any;
|
|
64
|
-
|
|
65
58
|
const canLiquidate = r.canLiquidate_ ?? r.canLiquidate ?? r[0];
|
|
66
59
|
const healthFactor = r.healthFactor ?? r[1];
|
|
67
60
|
const currentBonus = r.currentBonus ?? r[2];
|
|
@@ -74,7 +67,56 @@ export async function readCanLiquidate(params: {
|
|
|
74
67
|
throw new Error("Unexpected canLiquidate() return shape");
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
return { user
|
|
70
|
+
return { user, canLiquidate, healthFactor, currentBonus };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Normalized wrapper over `*.canLiquidate(user)`.
|
|
75
|
+
*/
|
|
76
|
+
// wraps: VarlaLiquidator.canLiquidate,VarlaMergeLiquidator.canLiquidate,VarlaConvertLiquidator.canLiquidate
|
|
77
|
+
export async function readCanLiquidate(params: {
|
|
78
|
+
liquidator: CanLiquidateLike;
|
|
79
|
+
user: Address;
|
|
80
|
+
}): Promise<ReadCanLiquidate> {
|
|
81
|
+
const raw = await params.liquidator.read.canLiquidate([params.user]);
|
|
82
|
+
return normalizeCanLiquidate(raw, params.user);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Multicall-chunked version of `readCanLiquidate`.
|
|
87
|
+
*/
|
|
88
|
+
// wraps: VarlaLiquidator.canLiquidate,VarlaMergeLiquidator.canLiquidate,VarlaConvertLiquidator.canLiquidate
|
|
89
|
+
export async function readManyCanLiquidate(params: {
|
|
90
|
+
liquidator: { address: Address };
|
|
91
|
+
client: { multicall: (args: any) => Promise<any> };
|
|
92
|
+
users: readonly Address[];
|
|
93
|
+
chunkSize?: number;
|
|
94
|
+
}): Promise<ReadCanLiquidate[]> {
|
|
95
|
+
const chunkSize = params.chunkSize ?? 256;
|
|
96
|
+
if (params.users.length === 0) return [];
|
|
97
|
+
|
|
98
|
+
const calls = params.users.map((user) => ({
|
|
99
|
+
address: params.liquidator.address,
|
|
100
|
+
abi: abis.VARLALIQUIDATOR_ABI,
|
|
101
|
+
functionName: "canLiquidate" as const,
|
|
102
|
+
args: [user] as const,
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
const res = await multicallChunks({
|
|
106
|
+
client: params.client as any,
|
|
107
|
+
contracts: calls as any,
|
|
108
|
+
chunkSize,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const out: ReadCanLiquidate[] = [];
|
|
112
|
+
for (let i = 0; i < res.length; i++) {
|
|
113
|
+
const r: any = (res as any[])[i];
|
|
114
|
+
if (r.status !== "success") {
|
|
115
|
+
throw new Error(`Liquidator canLiquidate multicall failed: ${String(r.error ?? "unknown")}`);
|
|
116
|
+
}
|
|
117
|
+
out.push(normalizeCanLiquidate(r.result, params.users[i]!));
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
78
120
|
}
|
|
79
121
|
|
|
80
122
|
type PreviewLiquidationLike = {
|
|
@@ -171,15 +213,7 @@ export type ReadBadDebtStatus = {
|
|
|
171
213
|
shortfall: bigint;
|
|
172
214
|
};
|
|
173
215
|
|
|
174
|
-
|
|
175
|
-
* Normalized wrapper over `VarlaLiquidator.checkBadDebt(user)`.
|
|
176
|
-
*/
|
|
177
|
-
// wraps: VarlaLiquidator.checkBadDebt
|
|
178
|
-
export async function readBadDebtStatus(params: {
|
|
179
|
-
liquidator: CheckBadDebtLike;
|
|
180
|
-
user: Address;
|
|
181
|
-
}): Promise<ReadBadDebtStatus> {
|
|
182
|
-
const raw = await params.liquidator.read.checkBadDebt([params.user]);
|
|
216
|
+
function normalizeBadDebtStatus(raw: unknown, user: Address): ReadBadDebtStatus {
|
|
183
217
|
const r: any = raw as any;
|
|
184
218
|
|
|
185
219
|
const hasBadDebt = r.hasBadDebt ?? r[0];
|
|
@@ -196,7 +230,56 @@ export async function readBadDebtStatus(params: {
|
|
|
196
230
|
throw new Error("Unexpected checkBadDebt() return shape");
|
|
197
231
|
}
|
|
198
232
|
|
|
199
|
-
return { user
|
|
233
|
+
return { user, hasBadDebt, collateralValue, debtValue, shortfall };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Normalized wrapper over `VarlaLiquidator.checkBadDebt(user)`.
|
|
238
|
+
*/
|
|
239
|
+
// wraps: VarlaLiquidator.checkBadDebt
|
|
240
|
+
export async function readBadDebtStatus(params: {
|
|
241
|
+
liquidator: CheckBadDebtLike;
|
|
242
|
+
user: Address;
|
|
243
|
+
}): Promise<ReadBadDebtStatus> {
|
|
244
|
+
const raw = await params.liquidator.read.checkBadDebt([params.user]);
|
|
245
|
+
return normalizeBadDebtStatus(raw, params.user);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Multicall-chunked version of `readBadDebtStatus`.
|
|
250
|
+
*/
|
|
251
|
+
// wraps: VarlaLiquidator.checkBadDebt
|
|
252
|
+
export async function readManyBadDebtStatus(params: {
|
|
253
|
+
liquidator: { address: Address };
|
|
254
|
+
client: { multicall: (args: any) => Promise<any> };
|
|
255
|
+
users: readonly Address[];
|
|
256
|
+
chunkSize?: number;
|
|
257
|
+
}): Promise<ReadBadDebtStatus[]> {
|
|
258
|
+
const chunkSize = params.chunkSize ?? 256;
|
|
259
|
+
if (params.users.length === 0) return [];
|
|
260
|
+
|
|
261
|
+
const calls = params.users.map((user) => ({
|
|
262
|
+
address: params.liquidator.address,
|
|
263
|
+
abi: abis.VARLALIQUIDATOR_ABI,
|
|
264
|
+
functionName: "checkBadDebt" as const,
|
|
265
|
+
args: [user] as const,
|
|
266
|
+
}));
|
|
267
|
+
|
|
268
|
+
const res = await multicallChunks({
|
|
269
|
+
client: params.client as any,
|
|
270
|
+
contracts: calls as any,
|
|
271
|
+
chunkSize,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const out: ReadBadDebtStatus[] = [];
|
|
275
|
+
for (let i = 0; i < res.length; i++) {
|
|
276
|
+
const r: any = (res as any[])[i];
|
|
277
|
+
if (r.status !== "success") {
|
|
278
|
+
throw new Error(`Liquidator checkBadDebt multicall failed: ${String(r.error ?? "unknown")}`);
|
|
279
|
+
}
|
|
280
|
+
out.push(normalizeBadDebtStatus(r.result, params.users[i]!));
|
|
281
|
+
}
|
|
282
|
+
return out;
|
|
200
283
|
}
|
|
201
284
|
|
|
202
285
|
type MergeLiquidatorLike = LiquidatorLike & {
|