@pearcurve/sdk 0.0.0-stage → 0.1.1

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.
Files changed (75) hide show
  1. package/LICENSE +64 -0
  2. package/README.md +122 -2
  3. package/dist/abis.d.ts +21 -0
  4. package/dist/abis.d.ts.map +1 -0
  5. package/dist/abis.js +39 -0
  6. package/dist/abis.js.map +1 -0
  7. package/dist/borrowerSubmitPreflight.d.ts +14 -0
  8. package/dist/borrowerSubmitPreflight.d.ts.map +1 -0
  9. package/dist/borrowerSubmitPreflight.js +28 -0
  10. package/dist/borrowerSubmitPreflight.js.map +1 -0
  11. package/dist/bps.d.ts +11 -0
  12. package/dist/bps.d.ts.map +1 -0
  13. package/dist/bps.js +25 -0
  14. package/dist/bps.js.map +1 -0
  15. package/dist/clients.d.ts +23 -0
  16. package/dist/clients.d.ts.map +1 -0
  17. package/dist/clients.js +59 -0
  18. package/dist/clients.js.map +1 -0
  19. package/dist/decodeError.d.ts +24 -0
  20. package/dist/decodeError.d.ts.map +1 -0
  21. package/dist/decodeError.js +358 -0
  22. package/dist/decodeError.js.map +1 -0
  23. package/dist/encoding.d.ts +18 -0
  24. package/dist/encoding.d.ts.map +1 -0
  25. package/dist/encoding.js +94 -0
  26. package/dist/encoding.js.map +1 -0
  27. package/dist/index.d.ts +18 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +18 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/lenderSubmitPreflight.d.ts +20 -0
  32. package/dist/lenderSubmitPreflight.d.ts.map +1 -0
  33. package/dist/lenderSubmitPreflight.js +42 -0
  34. package/dist/lenderSubmitPreflight.js.map +1 -0
  35. package/dist/loanPositions.d.ts +23 -0
  36. package/dist/loanPositions.d.ts.map +1 -0
  37. package/dist/loanPositions.js +37 -0
  38. package/dist/loanPositions.js.map +1 -0
  39. package/dist/marketStats.d.ts +70 -0
  40. package/dist/marketStats.d.ts.map +1 -0
  41. package/dist/marketStats.js +117 -0
  42. package/dist/marketStats.js.map +1 -0
  43. package/dist/networkConfig.d.ts +48 -0
  44. package/dist/networkConfig.d.ts.map +1 -0
  45. package/dist/networkConfig.js +48 -0
  46. package/dist/networkConfig.js.map +1 -0
  47. package/dist/pause.d.ts +20 -0
  48. package/dist/pause.d.ts.map +1 -0
  49. package/dist/pause.js +40 -0
  50. package/dist/pause.js.map +1 -0
  51. package/dist/reads.d.ts +187 -0
  52. package/dist/reads.d.ts.map +1 -0
  53. package/dist/reads.js +353 -0
  54. package/dist/reads.js.map +1 -0
  55. package/dist/strategies.d.ts +14 -0
  56. package/dist/strategies.d.ts.map +1 -0
  57. package/dist/strategies.js +49 -0
  58. package/dist/strategies.js.map +1 -0
  59. package/dist/txGas.d.ts +19 -0
  60. package/dist/txGas.d.ts.map +1 -0
  61. package/dist/txGas.js +37 -0
  62. package/dist/txGas.js.map +1 -0
  63. package/dist/types.d.ts +69 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +11 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/yieldMigrationPreflight.d.ts +29 -0
  68. package/dist/yieldMigrationPreflight.d.ts.map +1 -0
  69. package/dist/yieldMigrationPreflight.js +61 -0
  70. package/dist/yieldMigrationPreflight.js.map +1 -0
  71. package/dist/yieldSources.d.ts +33 -0
  72. package/dist/yieldSources.d.ts.map +1 -0
  73. package/dist/yieldSources.js +106 -0
  74. package/dist/yieldSources.js.map +1 -0
  75. package/package.json +47 -4
@@ -0,0 +1,23 @@
1
+ import { Contract, type ContractRunner, type TransactionResponse } from 'ethers';
2
+ import type { Address } from './types.js';
3
+ /**
4
+ * Resolves `Main.loanPositionToken()` and returns a contract instance with transfer ABI.
5
+ * @dev Requires a signer runner for writes.
6
+ */
7
+ export declare function getLoanPositionTokenFromMain(main: Contract): Promise<Contract>;
8
+ /**
9
+ * Transfers lender position NFT (`pcLOAN`) ownership.
10
+ * @returns Transaction response for `safeTransferFrom(from, to, loanId)`.
11
+ */
12
+ export declare function transferLoanPosition(loanPositionToken: Contract, from: Address, to: Address, loanId: bigint | number): Promise<TransactionResponse>;
13
+ /**
14
+ * Lists a position via `Main.listForSale(loanId, askPrice, paymentToken, expiry)`.
15
+ */
16
+ export declare function listLoanPosition(main: Contract, loanId: bigint | number, askPrice: bigint, paymentToken: Address, expiry: bigint): Promise<TransactionResponse>;
17
+ /**
18
+ * Delists a position via `Main.delistFromSale(loanId)`.
19
+ */
20
+ export declare function delistLoanPosition(main: Contract, loanId: bigint | number): Promise<TransactionResponse>;
21
+ /** Creates a typed contract instance for direct `pcLOAN` transfers. */
22
+ export declare function getLoanPositionToken(address: Address, runner: ContractRunner): Contract;
23
+ //# sourceMappingURL=loanPositions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loanPositions.d.ts","sourceRoot":"","sources":["../src/loanPositions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAGhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC;;;GAGG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAKpF;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,iBAAiB,EAAE,QAAQ,EAC3B,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,GAAG,MAAM,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAE9B;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,mBAAmB,CAAC,CAE9B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,GAAG,MAAM,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAE9B;AAED,uEAAuE;AACvE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,QAAQ,CAEvF"}
@@ -0,0 +1,37 @@
1
+ import { Contract } from 'ethers';
2
+ import { loanPositionTokenAbi } from './abis.js';
3
+ /**
4
+ * Resolves `Main.loanPositionToken()` and returns a contract instance with transfer ABI.
5
+ * @dev Requires a signer runner for writes.
6
+ */
7
+ export async function getLoanPositionTokenFromMain(main) {
8
+ const runner = main.runner;
9
+ if (!runner)
10
+ throw new Error('Main contract has no runner (attach provider or signer).');
11
+ const tokenAddress = await main.loanPositionToken();
12
+ return new Contract(tokenAddress, loanPositionTokenAbi, runner);
13
+ }
14
+ /**
15
+ * Transfers lender position NFT (`pcLOAN`) ownership.
16
+ * @returns Transaction response for `safeTransferFrom(from, to, loanId)`.
17
+ */
18
+ export async function transferLoanPosition(loanPositionToken, from, to, loanId) {
19
+ return loanPositionToken.safeTransferFrom(from, to, BigInt(loanId));
20
+ }
21
+ /**
22
+ * Lists a position via `Main.listForSale(loanId, askPrice, paymentToken, expiry)`.
23
+ */
24
+ export async function listLoanPosition(main, loanId, askPrice, paymentToken, expiry) {
25
+ return main.listForSale(BigInt(loanId), askPrice, paymentToken, expiry);
26
+ }
27
+ /**
28
+ * Delists a position via `Main.delistFromSale(loanId)`.
29
+ */
30
+ export async function delistLoanPosition(main, loanId) {
31
+ return main.delistFromSale(BigInt(loanId));
32
+ }
33
+ /** Creates a typed contract instance for direct `pcLOAN` transfers. */
34
+ export function getLoanPositionToken(address, runner) {
35
+ return new Contract(address, loanPositionTokenAbi, runner);
36
+ }
37
+ //# sourceMappingURL=loanPositions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loanPositions.js","sourceRoot":"","sources":["../src/loanPositions.ts"],"names":[],"mappings":"AAAA,OAAO,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lender intent row for aggregate stats (human token units). */
2
+ export type LenderIntentStatsRow = {
3
+ asset: string;
4
+ active: boolean;
5
+ maxPrincipal: number;
6
+ filledAmount: number;
7
+ };
8
+ /** Minimal loan row for aggregate stats (human token units). */
9
+ export type LoanStatsRow = {
10
+ asset: string;
11
+ collateral?: string;
12
+ principal: number;
13
+ collateralAmount?: number;
14
+ status?: number | string;
15
+ };
16
+ export type MarketAggregate = {
17
+ activeLoanCount: number;
18
+ /** @deprecated Prefer availableToLendUsd + yieldDepositedUsd */
19
+ suppliedUsd: number;
20
+ suppliedIncomplete: boolean;
21
+ availableToLendUsd: number;
22
+ availableToLendIncomplete: boolean;
23
+ yieldDepositedUsd: number;
24
+ yieldDepositedIncomplete: boolean;
25
+ collateralUsd: number | null;
26
+ collateralMissingPrice: boolean;
27
+ loanPrincipalUsd: number;
28
+ loanPrincipalIncomplete: boolean;
29
+ humanByAsset: Record<string, number>;
30
+ availableToLendHumanByAsset: Record<string, number>;
31
+ yieldTvlHumanByAsset: Record<string, number>;
32
+ };
33
+ /** Unfilled active lender intent headroom (human units per asset). */
34
+ export declare function availableToLendHumanByAsset(lenders: LenderIntentStatsRow[], assets: readonly string[]): Record<string, number>;
35
+ /** Principal on active loans per loan asset (human units). */
36
+ export declare function outstandingPrincipalHumanByAsset(activeLoans: LoanStatsRow[], assets: readonly string[]): Record<string, number>;
37
+ /** Idle lend capacity + outstanding principal per asset (human units). */
38
+ export declare function suppliedHumanByAsset(lenders: LenderIntentStatsRow[], activeLoans: LoanStatsRow[], assets: readonly string[]): Record<string, number>;
39
+ /** USD sum: includes only assets with an oracle price; `incomplete` if any non-zero position lacks a price. */
40
+ export declare function sumUsdHuman(humanByAsset: Record<string, number>, usdPerToken: Record<string, number | null | undefined>, assets: readonly string[]): {
41
+ usd: number;
42
+ incomplete: boolean;
43
+ };
44
+ /** Total collateral locked (USD) for active loans when oracle has each collateral token price. */
45
+ export declare function sumCollateralUsd(activeLoans: LoanStatsRow[], usdPerToken: Record<string, number | null | undefined>): {
46
+ usd: number | null;
47
+ missingPrice: boolean;
48
+ };
49
+ /** Principal outstanding in USD for active loans. */
50
+ export declare function sumLoanPrincipalUsd(activeLoans: LoanStatsRow[], usdPerToken: Record<string, number | null | undefined>): {
51
+ usd: number;
52
+ incomplete: boolean;
53
+ };
54
+ export type BuildMarketAggregateParams = {
55
+ lenders: LenderIntentStatsRow[];
56
+ loans: LoanStatsRow[];
57
+ usdPerToken: Record<string, number | null | undefined>;
58
+ /** Asset symbols to include (e.g. `['USDC','WETH']`). */
59
+ assets: readonly string[];
60
+ /** Optional per-symbol TVL in yield adapters (protocol or wallet scope). */
61
+ yieldTvlHumanByAsset?: Record<string, number>;
62
+ };
63
+ /**
64
+ * Protocol- or wallet-scoped market aggregates for dashboard KPIs.
65
+ * Compose with SDK reads: intents (`readLenderIntent`), loans (`readLoanBundle`),
66
+ * yield TVL (`readYieldSourceTotalAssets`), wallet yield (`readAllYieldSourceBalances`),
67
+ * and oracle prices (`readAssetPrice` / `readOraclePairPrice`).
68
+ */
69
+ export declare function buildMarketAggregate(p: BuildMarketAggregateParams): MarketAggregate;
70
+ //# sourceMappingURL=marketStats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marketStats.d.ts","sourceRoot":"","sources":["../src/marketStats.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,gEAAgE;AAChE,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACzB,CAAA;A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,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EACtD,MAAM,EAAE,SAAS,MAAM,EAAE,GACxB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAUtC;AAED,kGAAkG;AAClG,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,YAAY,EAAE,EAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GACrD;IAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAe/C;AAED,qDAAqD;AACrD,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,YAAY,EAAE,EAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GACrD;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAStC;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,oBAAoB,EAAE,CAAA;IAC/B,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;IACtD,yDAAyD;IACzD,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IACzB,4EAA4E;IAC5E,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9C,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,0BAA0B,GAAG,eAAe,CA0BnF"}
@@ -0,0 +1,117 @@
1
+ function isActiveLoan(l) {
2
+ const s = l?.status;
3
+ if (typeof s === 'number')
4
+ return s === 0 || s === 1;
5
+ if (typeof s !== 'string')
6
+ return false;
7
+ const norm = s.trim().toLowerCase();
8
+ return norm === 'active' || norm === 'listed';
9
+ }
10
+ /** Unfilled active lender intent headroom (human units per asset). */
11
+ export function availableToLendHumanByAsset(lenders, assets) {
12
+ const out = {};
13
+ for (const asset of assets) {
14
+ out[asset] = lenders
15
+ .filter((i) => i.asset === asset && i.active)
16
+ .reduce((s, i) => s + Math.max(0, i.maxPrincipal - i.filledAmount), 0);
17
+ }
18
+ return out;
19
+ }
20
+ /** Principal on active loans per loan asset (human units). */
21
+ export function outstandingPrincipalHumanByAsset(activeLoans, assets) {
22
+ const out = {};
23
+ for (const asset of assets) {
24
+ out[asset] = activeLoans.filter((l) => l.asset === asset).reduce((s, l) => s + l.principal, 0);
25
+ }
26
+ return out;
27
+ }
28
+ /** Idle lend capacity + outstanding principal per asset (human units). */
29
+ export function suppliedHumanByAsset(lenders, activeLoans, assets) {
30
+ const avail = availableToLendHumanByAsset(lenders, assets);
31
+ const principal = outstandingPrincipalHumanByAsset(activeLoans, assets);
32
+ const out = {};
33
+ for (const asset of assets) {
34
+ out[asset] = (avail[asset] ?? 0) + (principal[asset] ?? 0);
35
+ }
36
+ return out;
37
+ }
38
+ /** USD sum: includes only assets with an oracle price; `incomplete` if any non-zero position lacks a price. */
39
+ export function sumUsdHuman(humanByAsset, usdPerToken, assets) {
40
+ let total = 0;
41
+ let incomplete = false;
42
+ for (const asset of assets) {
43
+ const human = humanByAsset[asset] ?? 0;
44
+ const px = usdPerToken[asset];
45
+ if (px != null)
46
+ total += human * px;
47
+ else if (human > 0)
48
+ incomplete = true;
49
+ }
50
+ return { usd: total, incomplete };
51
+ }
52
+ /** Total collateral locked (USD) for active loans when oracle has each collateral token price. */
53
+ export function sumCollateralUsd(activeLoans, usdPerToken) {
54
+ if (!activeLoans.length)
55
+ return { usd: 0, missingPrice: false };
56
+ let total = 0;
57
+ let missingPrice = false;
58
+ for (const l of activeLoans) {
59
+ const col = l.collateral;
60
+ const px = col != null ? usdPerToken[col] : null;
61
+ const amt = l.collateralAmount ?? 0;
62
+ if (px != null) {
63
+ total += amt * px;
64
+ }
65
+ else if (amt > 0) {
66
+ missingPrice = true;
67
+ }
68
+ }
69
+ return { usd: missingPrice ? null : total, missingPrice };
70
+ }
71
+ /** Principal outstanding in USD for active loans. */
72
+ export function sumLoanPrincipalUsd(activeLoans, usdPerToken) {
73
+ let total = 0;
74
+ let incomplete = false;
75
+ for (const l of activeLoans) {
76
+ const px = usdPerToken[l.asset];
77
+ if (px != null)
78
+ total += l.principal * px;
79
+ else if (l.principal > 0)
80
+ incomplete = true;
81
+ }
82
+ return { usd: total, incomplete };
83
+ }
84
+ /**
85
+ * Protocol- or wallet-scoped market aggregates for dashboard KPIs.
86
+ * Compose with SDK reads: intents (`readLenderIntent`), loans (`readLoanBundle`),
87
+ * yield TVL (`readYieldSourceTotalAssets`), wallet yield (`readAllYieldSourceBalances`),
88
+ * and oracle prices (`readAssetPrice` / `readOraclePairPrice`).
89
+ */
90
+ export function buildMarketAggregate(p) {
91
+ const { lenders, loans, usdPerToken, assets, yieldTvlHumanByAsset } = p;
92
+ const activeLoans = loans.filter(isActiveLoan);
93
+ const yieldExtra = yieldTvlHumanByAsset ?? {};
94
+ const availableHuman = availableToLendHumanByAsset(lenders, assets);
95
+ const humanByAsset = suppliedHumanByAsset(lenders, activeLoans, assets);
96
+ const availableToLend = sumUsdHuman(availableHuman, usdPerToken, assets);
97
+ const yieldDeposited = sumUsdHuman(yieldExtra, usdPerToken, assets);
98
+ const collateral = sumCollateralUsd(activeLoans, usdPerToken);
99
+ const principal = sumLoanPrincipalUsd(activeLoans, usdPerToken);
100
+ return {
101
+ activeLoanCount: activeLoans.length,
102
+ suppliedUsd: availableToLend.usd + principal.usd,
103
+ suppliedIncomplete: availableToLend.incomplete || principal.incomplete,
104
+ availableToLendUsd: availableToLend.usd,
105
+ availableToLendIncomplete: availableToLend.incomplete,
106
+ yieldDepositedUsd: yieldDeposited.usd,
107
+ yieldDepositedIncomplete: yieldDeposited.incomplete,
108
+ collateralUsd: collateral.usd,
109
+ collateralMissingPrice: collateral.missingPrice,
110
+ loanPrincipalUsd: principal.usd,
111
+ loanPrincipalIncomplete: principal.incomplete,
112
+ humanByAsset,
113
+ availableToLendHumanByAsset: availableHuman,
114
+ yieldTvlHumanByAsset: yieldExtra,
115
+ };
116
+ }
117
+ //# sourceMappingURL=marketStats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marketStats.js","sourceRoot":"","sources":["../src/marketStats.ts"],"names":[],"mappings":"AAmCA,SAAS,YAAY,CAAC,CAAe;IACnC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpD,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACvC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACnC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,CAAA;AAC/C,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,2BAA2B,CACzC,OAA+B,EAC/B,MAAyB;IAEzB,MAAM,GAAG,GAA2B,EAAE,CAAA;IACtC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO;aACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC;aAC5C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,gCAAgC,CAC9C,WAA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,yBAAyB,EAAE,eAAe,CAAC,UAAU;QACrD,iBAAiB,EAAE,cAAc,CAAC,GAAG;QACrC,wBAAwB,EAAE,cAAc,CAAC,UAAU;QACnD,aAAa,EAAE,UAAU,CAAC,GAAG;QAC7B,sBAAsB,EAAE,UAAU,CAAC,YAAY;QAC/C,gBAAgB,EAAE,SAAS,CAAC,GAAG;QAC/B,uBAAuB,EAAE,SAAS,CAAC,UAAU;QAC7C,YAAY;QACZ,2BAA2B,EAAE,cAAc;QAC3C,oBAAoB,EAAE,UAAU;KACjC,CAAA;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { Address } from './types.js';
2
+ /**
3
+ * Pearcurve deployment addresses for a single chain.
4
+ * Keys in {@link deployments} are EIP-155 chain IDs as decimal strings.
5
+ */
6
+ export type PearcurveDeployment = {
7
+ main: Address;
8
+ matchingEngine: Address;
9
+ intentRegistry: Address;
10
+ intentRegistryViews?: Address;
11
+ loanManager?: Address;
12
+ loanManagerValidation?: Address;
13
+ yieldSourceRegistry?: Address;
14
+ priceOracle?: Address;
15
+ loanHealthViewer?: Address;
16
+ protocolViewer?: Address;
17
+ secondaryMarket?: Address;
18
+ usdc?: Address;
19
+ usdt?: Address;
20
+ weth?: Address;
21
+ wbtc?: Address;
22
+ aaveV3YieldSource?: Address;
23
+ compoundV3YieldSourceUsdc?: Address;
24
+ compoundV3YieldSourceUsdt?: Address;
25
+ compoundV3YieldSourceWeth?: Address;
26
+ compoundV3YieldSourceWbtc?: Address;
27
+ eventLogsFromBlock?: number;
28
+ /**
29
+ * Set only for leftover June Arc deploys that still use `subAccountId` + `collateralConfigs[]`.
30
+ * Current Arc deploys omit this.
31
+ */
32
+ legacyIntentSubmit?: boolean;
33
+ };
34
+ export declare const PearcurveChainId: {
35
+ readonly LocalAnvil: 31337n;
36
+ readonly EthereumSepolia: 11155111n;
37
+ readonly EthereumMainnet: 1n;
38
+ /** Circle Arc mainnet — native gas is USDC (18 decimals). */
39
+ readonly ArcMainnet: 5042n;
40
+ readonly ArcTestnet: 5042002n;
41
+ };
42
+ /** Auto-synced from @pearcurve/contracts deployments/*.json by scripts/sync-deployments.mjs */
43
+ export declare const deployments: Partial<Record<string, PearcurveDeployment>>;
44
+ export declare function getDeployment(chainId: bigint): PearcurveDeployment | undefined;
45
+ export declare function requireDeployment(chainId: bigint): PearcurveDeployment;
46
+ /** Canonical protocol address from the SDK map. Env overlays belong in the app, not here. */
47
+ export declare function sdkDeploymentAddress(chainId: bigint, key: keyof PearcurveDeployment): Address | undefined;
48
+ //# sourceMappingURL=networkConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networkConfig.d.ts","sourceRoot":"","sources":["../src/networkConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,cAAc,EAAE,OAAO,CAAA;IACvB,cAAc,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,gBAAgB;;;;IAI3B,6DAA6D;;;CAGrD,CAAA;AAEV,+FAA+F;AAC/F,eAAO,MAAM,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAuBpE,CAAA;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAE9E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAItE;AAED,6FAA6F;AAC7F,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,mBAAmB,GAC7B,OAAO,GAAG,SAAS,CAGrB"}
@@ -0,0 +1,48 @@
1
+ export const PearcurveChainId = {
2
+ LocalAnvil: 31337n,
3
+ EthereumSepolia: 11155111n,
4
+ EthereumMainnet: 1n,
5
+ /** Circle Arc mainnet — native gas is USDC (18 decimals). */
6
+ ArcMainnet: 5042n,
7
+ ArcTestnet: 5042002n,
8
+ };
9
+ /** Auto-synced from @pearcurve/contracts deployments/*.json by scripts/sync-deployments.mjs */
10
+ export const deployments = {
11
+ '5042002': {
12
+ main: '0x061ca0cc2a30853641d6245c292157ebcffaa273',
13
+ matchingEngine: '0x3e06f73074b938198f66c322010fa4e2ac0d52a3',
14
+ intentRegistry: '0x0dda05ff98996fcf2dc9e35952577e0e3a9cf46b',
15
+ intentRegistryViews: '0xd642f514b7b82838cf24279948bcc6b1663e4a5e',
16
+ loanManager: '0x0028bcc9bb747cac8cf16273845262f0f8a3be2c',
17
+ loanManagerValidation: '0x0e17509459a68425bdbdb4282e99598bebdc0276',
18
+ yieldSourceRegistry: '0x23b520d6b0d75401af71344f9823044a33aebc49',
19
+ priceOracle: '0x2057ac2eea9c3b7acff700175338b734e3a73e39',
20
+ loanHealthViewer: '0x05ee4cb10c04c173f56e5d75d0e3b949f9071910',
21
+ protocolViewer: '0x7450fe6e80989fd6cccdb7a1a8d9112ec2a5aff7',
22
+ secondaryMarket: '0x1748ad018e6699a56ccf5747048b390b4442dc9b',
23
+ usdc: '0x84e6255622b4bcbe7e7b07ed8d733c0e1575744e',
24
+ usdt: '0x4b6d333400744a4d77e757f5becf2c84215244c3',
25
+ weth: '0xaaf7a7a278a8f446b732160a9f63532309961ab5',
26
+ wbtc: '0x96a126e3a091490ab5cd20ce005c7c300545c569',
27
+ aaveV3YieldSource: '0x956932fcc2c3c88e21f4a9d6a6fe6b8b2d3e7fa8',
28
+ compoundV3YieldSourceUsdc: '0xaf129320ee2579ac3efefe68667b6247f2c9d858',
29
+ compoundV3YieldSourceUsdt: '0x552e9cdb95f7049f53e69e853111a571c6db9639',
30
+ compoundV3YieldSourceWeth: '0x409b212847dbcbde882c58010d797f955b3e8b5c',
31
+ compoundV3YieldSourceWbtc: '0x48cf73f8a7574dc40eedfd9e23e426ff337b1104'
32
+ }
33
+ };
34
+ export function getDeployment(chainId) {
35
+ return deployments[chainId.toString()];
36
+ }
37
+ export function requireDeployment(chainId) {
38
+ const d = getDeployment(chainId);
39
+ if (!d)
40
+ throw new Error('No Pearcurve deployment configured for chain id ' + chainId.toString());
41
+ return d;
42
+ }
43
+ /** Canonical protocol address from the SDK map. Env overlays belong in the app, not here. */
44
+ export function sdkDeploymentAddress(chainId, key) {
45
+ const value = getDeployment(chainId)?.[key];
46
+ return typeof value === 'string' && value.startsWith('0x') ? value : undefined;
47
+ }
48
+ //# sourceMappingURL=networkConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networkConfig.js","sourceRoot":"","sources":["../src/networkConfig.ts"],"names":[],"mappings":"AAmCA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,UAAU,EAAE,MAAM;IAClB,eAAe,EAAE,SAAS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AA;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAChF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ContractRunner } from 'ethers';
2
+ import type { Address } from './types.js';
3
+ export declare enum MarketFeature {
4
+ Deposit = 0,
5
+ Withdraw = 1,
6
+ Borrow = 2,
7
+ Repay = 3,
8
+ Liquidate = 4,
9
+ Refinance = 5,
10
+ Match = 6,
11
+ Secondary = 7
12
+ }
13
+ /** Reads OpenZeppelin `Pausable.paused()` from Main. */
14
+ export declare function isProtocolPaused(mainAddress: Address, runner: ContractRunner): Promise<boolean>;
15
+ /** Reads market-level pause flag from Main. */
16
+ export declare function isMarketPaused(mainAddress: Address, market: Address, runner: ContractRunner): Promise<boolean>;
17
+ /** Reads market-feature-level pause flag from Main. */
18
+ export declare function isMarketFeaturePaused(mainAddress: Address, market: Address, feature: MarketFeature | number, runner: ContractRunner): Promise<boolean>;
19
+ export declare function mapPauseError(error: unknown): string | null;
20
+ //# sourceMappingURL=pause.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pause.d.ts","sourceRoot":"","sources":["../src/pause.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAI5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,oBAAY,aAAa;IACvB,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,KAAK,IAAI;IACT,SAAS,IAAI;IACb,SAAS,IAAI;IACb,KAAK,IAAI;IACT,SAAS,IAAI;CACd;AAED,wDAAwD;AACxD,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAGrG;AAED,+CAA+C;AAC/C,wBAAsB,cAAc,CAClC,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,uDAAuD;AACvD,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,aAAa,GAAG,MAAM,EAC/B,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAW3D"}
package/dist/pause.js ADDED
@@ -0,0 +1,40 @@
1
+ import { getMain } from './clients.js';
2
+ import { formatProtocolError } from './decodeError.js';
3
+ export var MarketFeature;
4
+ (function (MarketFeature) {
5
+ MarketFeature[MarketFeature["Deposit"] = 0] = "Deposit";
6
+ MarketFeature[MarketFeature["Withdraw"] = 1] = "Withdraw";
7
+ MarketFeature[MarketFeature["Borrow"] = 2] = "Borrow";
8
+ MarketFeature[MarketFeature["Repay"] = 3] = "Repay";
9
+ MarketFeature[MarketFeature["Liquidate"] = 4] = "Liquidate";
10
+ MarketFeature[MarketFeature["Refinance"] = 5] = "Refinance";
11
+ MarketFeature[MarketFeature["Match"] = 6] = "Match";
12
+ MarketFeature[MarketFeature["Secondary"] = 7] = "Secondary";
13
+ })(MarketFeature || (MarketFeature = {}));
14
+ /** Reads OpenZeppelin `Pausable.paused()` from Main. */
15
+ export async function isProtocolPaused(mainAddress, runner) {
16
+ const main = getMain(mainAddress, runner);
17
+ return Boolean(await main.paused());
18
+ }
19
+ /** Reads market-level pause flag from Main. */
20
+ export async function isMarketPaused(mainAddress, market, runner) {
21
+ const main = getMain(mainAddress, runner);
22
+ return Boolean(await main.isMarketPaused(market));
23
+ }
24
+ /** Reads market-feature-level pause flag from Main. */
25
+ export async function isMarketFeaturePaused(mainAddress, market, feature, runner) {
26
+ const main = getMain(mainAddress, runner);
27
+ return Boolean(await main.isMarketFeaturePaused(market, feature));
28
+ }
29
+ export function mapPauseError(error) {
30
+ const formatted = formatProtocolError(error);
31
+ if (!formatted)
32
+ return null;
33
+ const lower = formatted.toLowerCase();
34
+ if (lower.includes('paused') ||
35
+ lower.includes('pause')) {
36
+ return formatted;
37
+ }
38
+ return null;
39
+ }
40
+ //# sourceMappingURL=pause.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pause.js","sourceRoot":"","sources":["../src/pause.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAGtD,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,uDAAW,CAAA;IACX,yDAAY,CAAA;IACZ,qDAAU,CAAA;IACV,mDAAS,CAAA;IACT,2DAAa,CAAA;IACb,2DAAa,CAAA;IACb,mDAAS,CAAA;IACT,2DAAa,CAAA;AACf,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAED,wDAAwD;AACxD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,WAAoB,EAAE,MAAsB;IACjF,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACzC,OAAO,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;AACrC,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,WAAoB,EACpB,MAAe,EACf,MAAsB;IAEtB,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACzC,OAAO,OAAO,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;AACnD,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,WAAoB,EACpB,MAAe,EACf,OAA+B,EAC/B,MAAsB;IAEtB,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACzC,OAAO,OAAO,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAC5C,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAA;IAC3B,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;IACrC,IACE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACxB,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EACvB,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,187 @@
1
+ import type { ContractRunner } from 'ethers';
2
+ import { getLoanManager } from './clients.js';
3
+ import { MarketFeature } from './pause.js';
4
+ import type { Address } from './types.js';
5
+ export { MarketFeature };
6
+ export type LoanAgreementExtras = {
7
+ strategy: string | null;
8
+ lltv: bigint;
9
+ yieldSource: string | null;
10
+ blockEarlyRepayment: boolean;
11
+ };
12
+ export type LoanReadBundle = {
13
+ agreement: Awaited<ReturnType<ReturnType<typeof getLoanManager>['getAgreement']>>;
14
+ } & LoanAgreementExtras;
15
+ export type YieldSourceBalancePack = {
16
+ sources: string[];
17
+ balances: bigint[];
18
+ };
19
+ /** Full loan row inputs for UI formatters (`getAgreement` + per-loan metadata). */
20
+ export declare function readLoanBundle(loanManagerAddress: Address, loanId: bigint, runner: ContractRunner): Promise<LoanReadBundle>;
21
+ /** `Main.getAllYieldSourceBalances(owner, asset)`. */
22
+ export declare function readAllYieldSourceBalances(mainAddress: Address, owner: Address, asset: Address, runner: ContractRunner): Promise<YieldSourceBalancePack>;
23
+ /** `LoanHealthViewer.getLoanHealth(loanId)`. */
24
+ export declare function readLoanHealth(viewerAddress: Address, loanId: bigint, runner: ContractRunner): Promise<any>;
25
+ /** Core `IntentRegistry` address behind a views facade. */
26
+ export declare function readIntentRegistryAddress(viewsAddress: Address, runner: ContractRunner): Promise<Address>;
27
+ /** `IntentRegistry.committedCollateral(owner, collateral)` — on-chain borrower intent bookings only. */
28
+ export declare function readCommittedCollateral(intentRegistryAddress: Address, owner: Address, collateral: Address, runner: ContractRunner): Promise<bigint>;
29
+ /** `IntentRegistry.committedCapacity(owner, yieldSource, asset)` — on-chain lender intent bookings only. */
30
+ export declare function readCommittedCapacity(intentRegistryAddress: Address, owner: Address, yieldSource: Address, asset: Address, runner: ContractRunner): Promise<bigint>;
31
+ export declare function readLenderIntent(viewsAddress: Address, intentId: bigint, runner: ContractRunner): Promise<any>;
32
+ export declare function readBorrowerIntent(viewsAddress: Address, intentId: bigint, runner: ContractRunner): Promise<any>;
33
+ /** `PriceOracle.getAssetPrice(asset)` when supported by deployment. */
34
+ export declare function readAssetPrice(oracleAddress: Address, asset: Address, runner: ContractRunner): Promise<bigint>;
35
+ /** `IPriceOracle.getPrice(collateral, quote)` (e.g. mock testnet oracle). */
36
+ export declare function readOraclePairPrice(oracleAddress: Address, collateral: Address, quote: Address, runner: ContractRunner): Promise<bigint>;
37
+ /** `IYieldSource.totalAssets(asset)`. */
38
+ export declare function readYieldSourceTotalAssets(yieldSourceAddress: Address, asset: Address, runner: ContractRunner): Promise<bigint>;
39
+ export type ProtocolTotalsSnapshot = {
40
+ activeLoanCount: bigint;
41
+ nextLoanId: bigint;
42
+ nextLenderIntentId: bigint;
43
+ nextBorrowerIntentId: bigint;
44
+ };
45
+ export type LoanSummaryRow = {
46
+ loanId: bigint;
47
+ status: number;
48
+ lenderOwner: string;
49
+ borrowerOwner: string;
50
+ asset: string;
51
+ collateral: string;
52
+ principal: bigint;
53
+ collateralAmount: bigint;
54
+ interestRate: bigint;
55
+ lltv: number;
56
+ startTime: bigint;
57
+ maturity: bigint;
58
+ };
59
+ export type LenderIntentSummaryRow = {
60
+ intentId: bigint;
61
+ owner: string;
62
+ asset: string;
63
+ maxPrincipal: bigint;
64
+ filledAmount: bigint;
65
+ minRate: bigint;
66
+ expiry: bigint;
67
+ active: boolean;
68
+ yieldSource: string;
69
+ };
70
+ export type BorrowerIntentSummaryRow = {
71
+ intentId: bigint;
72
+ owner: string;
73
+ asset: string;
74
+ principal: bigint;
75
+ filledAmount: bigint;
76
+ maxRate: bigint;
77
+ duration: bigint;
78
+ collateral: string;
79
+ expiry: bigint;
80
+ active: boolean;
81
+ };
82
+ export type YieldTvlBreakdownRow = {
83
+ yieldSource: string;
84
+ asset: string;
85
+ totalAssets: bigint;
86
+ name: string;
87
+ };
88
+ export type YieldApyRow = {
89
+ yieldSource: string;
90
+ asset: string;
91
+ apyBps: bigint;
92
+ };
93
+ export type MarketCapRow = {
94
+ asset: string;
95
+ defaultSupplyCap: bigint;
96
+ defaultBorrowCap: bigint;
97
+ };
98
+ export type WalletYieldBalanceRow = {
99
+ asset: string;
100
+ yieldSource: string;
101
+ balance: bigint;
102
+ };
103
+ export type ProtocolSnapshotBundle = {
104
+ totals: ProtocolTotalsSnapshot;
105
+ assetPrices: bigint[];
106
+ yieldTvl: Array<{
107
+ asset: string;
108
+ totalAssets: bigint;
109
+ }>;
110
+ yieldBreakdown: YieldTvlBreakdownRow[];
111
+ yieldApys: YieldApyRow[];
112
+ marketCaps: MarketCapRow[];
113
+ };
114
+ /** `ProtocolViewer.getProtocolTotals()`. */
115
+ export declare function readProtocolTotals(viewerAddress: Address, runner: ContractRunner): Promise<ProtocolTotalsSnapshot>;
116
+ /** `ProtocolViewer.getLoanSummaries(startId, limit)`. */
117
+ export declare function readLoanSummaries(viewerAddress: Address, startId: bigint, limit: bigint, runner: ContractRunner): Promise<LoanSummaryRow[]>;
118
+ /** `ProtocolViewer.getProtocolSnapshot(assets)` — single-call landing fast slice. */
119
+ export declare function readProtocolSnapshot(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<ProtocolSnapshotBundle>;
120
+ export type SummaryPage<T> = {
121
+ rows: T[];
122
+ /** `startId` for the next page, or 0 once the id range up to `next{Lender,Borrower}IntentId` is exhausted. */
123
+ nextId: bigint;
124
+ };
125
+ /** `ProtocolViewer.getLenderIntentSummaries(startId, limit)` — returns `(rows, nextId)`. */
126
+ export declare function readLenderIntentSummaries(viewerAddress: Address, startId: bigint, limit: bigint, runner: ContractRunner): Promise<SummaryPage<LenderIntentSummaryRow>>;
127
+ /** `ProtocolViewer.getBorrowerIntentSummaries(startId, limit)` — returns `(rows, nextId)`. */
128
+ export declare function readBorrowerIntentSummaries(viewerAddress: Address, startId: bigint, limit: bigint, runner: ContractRunner): Promise<SummaryPage<BorrowerIntentSummaryRow>>;
129
+ /** `ProtocolViewer.getLoanSummariesByIds(loanIds)`. */
130
+ export declare function readLoanSummariesByIds(viewerAddress: Address, loanIds: bigint[], runner: ContractRunner): Promise<LoanSummaryRow[]>;
131
+ /** `ProtocolViewer.getLenderIntentSummariesByIds(intentIds)`. */
132
+ export declare function readLenderIntentSummariesByIds(viewerAddress: Address, intentIds: bigint[], runner: ContractRunner): Promise<LenderIntentSummaryRow[]>;
133
+ /** `ProtocolViewer.getBorrowerIntentSummariesByIds(intentIds)`. */
134
+ export declare function readBorrowerIntentSummariesByIds(viewerAddress: Address, intentIds: bigint[], runner: ContractRunner): Promise<BorrowerIntentSummaryRow[]>;
135
+ /** `ProtocolViewer.getYieldTvlBreakdown(assets)`. */
136
+ export declare function readYieldTvlBreakdownFromViewer(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<YieldTvlBreakdownRow[]>;
137
+ /** `ProtocolViewer.getYieldTvlByAssets(assets)`. */
138
+ export declare function readYieldTvlByAssetsFromViewer(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<Array<{
139
+ asset: string;
140
+ totalAssets: bigint;
141
+ }>>;
142
+ /** `ProtocolViewer.getAssetPricesUsd(assets)`. */
143
+ export declare function readAssetPricesFromViewer(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<bigint[]>;
144
+ /** `ProtocolViewer.getYieldApys(assets)`. */
145
+ export declare function readYieldApysFromViewer(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<YieldApyRow[]>;
146
+ /** `ProtocolViewer.getMarketCaps(assets)`. */
147
+ export declare function readMarketCapsFromViewer(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<MarketCapRow[]>;
148
+ /** `ProtocolViewer.getWalletYieldSnapshot(user, assets)`. */
149
+ export declare function readWalletYieldSnapshot(viewerAddress: Address, user: Address, assetAddresses: Address[], runner: ContractRunner): Promise<WalletYieldBalanceRow[]>;
150
+ /** `ProtocolViewer.getActiveLenderIntentCounts(assets)`. */
151
+ export declare function readActiveLenderIntentCounts(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<bigint[]>;
152
+ /** `ProtocolViewer.getActiveBorrowerIntentCounts(assets)`. */
153
+ export declare function readActiveBorrowerIntentCounts(viewerAddress: Address, assetAddresses: Address[], runner: ContractRunner): Promise<bigint[]>;
154
+ export type PaginatedIds = {
155
+ ids: bigint[];
156
+ nextId: bigint;
157
+ };
158
+ /** `IntentRegistryViews.getActiveLenderIntents(asset)` — full rate-sorted list, unbounded. */
159
+ export declare function readActiveLenderIntents(viewsAddress: Address, asset: Address, runner: ContractRunner): Promise<bigint[]>;
160
+ /** `IntentRegistryViews.getActiveLenderIntentsCount(asset)`. */
161
+ export declare function readActiveLenderIntentsCount(viewsAddress: Address, asset: Address, runner: ContractRunner): Promise<bigint>;
162
+ /** `IntentRegistryViews.getActiveLenderIntentsPaginated(asset, startId, limit)` — rate-sorted, cursor-based. */
163
+ export declare function readActiveLenderIntentsPaginated(viewsAddress: Address, asset: Address, startId: bigint, limit: bigint, runner: ContractRunner): Promise<PaginatedIds>;
164
+ /** `IntentRegistryViews.getActiveBorrowerIntents(asset)` — full FIFO (oldest-first) list, unbounded. */
165
+ export declare function readActiveBorrowerIntents(viewsAddress: Address, asset: Address, runner: ContractRunner): Promise<bigint[]>;
166
+ /** `IntentRegistryViews.getActiveBorrowerIntentsCount(asset)`. */
167
+ export declare function readActiveBorrowerIntentsCount(viewsAddress: Address, asset: Address, runner: ContractRunner): Promise<bigint>;
168
+ /** `IntentRegistryViews.getActiveBorrowerIntentsPaginated(asset, startId, limit)` — FIFO, cursor-based. */
169
+ export declare function readActiveBorrowerIntentsPaginated(viewsAddress: Address, asset: Address, startId: bigint, limit: bigint, runner: ContractRunner): Promise<PaginatedIds>;
170
+ export type PauseSnapshot = {
171
+ protocolPaused: boolean;
172
+ /** Lowercase market asset address → paused */
173
+ marketPausedByAddress: Record<string, boolean>;
174
+ /** `MarketFeature` enum name → paused (sampled on first market) */
175
+ featurePausedByName: Record<string, boolean>;
176
+ };
177
+ /**
178
+ * Batch pause reads for risk UI.
179
+ * Feature flags are read against `sampleMarketForFeatures` (first market if omitted).
180
+ */
181
+ export declare function fetchPauseSnapshot(mainAddress: Address, marketAddresses: Address[], runner: ContractRunner, sampleMarketForFeatures?: Address | null): Promise<PauseSnapshot>;
182
+ /**
183
+ * Protocol → market → feature pause preflight (user-facing reason or null).
184
+ * @param runner ethers provider/signer attached to the target chain
185
+ */
186
+ export declare function preflightPauseReason(mainAddress: Address, market: Address, feature: MarketFeature | number | null | undefined, runner: ContractRunner): Promise<string | null>;
187
+ //# sourceMappingURL=reads.d.ts.map