@gvnrdao/dh-sdk 0.0.338 → 0.0.339
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/browser/dist/browser.js +1 -1
- package/dist/graphs/diamond-hands.d.ts +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +213 -32
- package/dist/index.mjs +214 -33
- package/dist/interfaces/chunks/loan-operations.i.d.ts +34 -0
- package/dist/modules/diamond-hands-sdk.d.ts +10 -0
- package/dist/modules/loan/loan-query.module.d.ts +12 -1
- package/dist/utils/borrower-ucd-debt-summary.d.ts +44 -0
- package/package.json +2 -2
|
@@ -13,7 +13,7 @@ import { Result } from "../../types/result";
|
|
|
13
13
|
import { SDKError } from "../../utils/error-handler";
|
|
14
14
|
import type { BitcoinOperations } from "../bitcoin/bitcoin-operations.module";
|
|
15
15
|
import type { Cache } from "../cache/cache-manager.module";
|
|
16
|
-
import type { LoanData, LoanDataDetail, PaginatedLoansResponse } from "../../interfaces/chunks/loan-operations.i";
|
|
16
|
+
import type { BorrowerUcdDebtSummary, LoanData, LoanDataDetail, PaginatedLoansResponse } from "../../interfaces/chunks/loan-operations.i";
|
|
17
17
|
import type { LoanEvents, LoanEventsFilter } from "../../types/event-types";
|
|
18
18
|
import { DiamondHandsGraphClient } from "@graphs/diamond-hands";
|
|
19
19
|
import { type Provider } from "ethers";
|
|
@@ -141,6 +141,17 @@ export declare class LoanQuery {
|
|
|
141
141
|
* @returns Paginated loans for borrower
|
|
142
142
|
*/
|
|
143
143
|
getLoansByBorrower(borrower: string, pagination?: PaginationParams, orderBy?: "createdAt" | "lastUpdatedAt" | "ucdDebt", orderDirection?: "asc" | "desc"): Promise<Result<PaginatedLoansResponse, SDKError>>;
|
|
144
|
+
/**
|
|
145
|
+
* Combined UCD debt + by-status counts for a borrower from ONE pass over the
|
|
146
|
+
* subgraph's raw rows (`graphClient.getBorrowerDebtRows`): BigInt wei sum, strict
|
|
147
|
+
* status labels, `source: "subgraph"`.
|
|
148
|
+
*
|
|
149
|
+
* INDEXED figure, not a transaction input — the subgraph lags writes. Anything that
|
|
150
|
+
* sizes a repayment reads the chain (`getPositionDetailsView`). Fails loud: a page
|
|
151
|
+
* failure or the page cap is a SUBGRAPH-category failure carrying the cause; there
|
|
152
|
+
* is no partial total.
|
|
153
|
+
*/
|
|
154
|
+
getBorrowerUcdDebtSummary(borrower: string): Promise<Result<BorrowerUcdDebtSummary, SDKError>>;
|
|
144
155
|
/**
|
|
145
156
|
* Get active loans (status = ACTIVE)
|
|
146
157
|
*
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers behind `getBorrowerUcdDebtSummary`.
|
|
3
|
+
*
|
|
4
|
+
* Kept free of the graph client so the arithmetic and the pagination loop are
|
|
5
|
+
* unit-testable without a subgraph: the loop takes a page fetcher, the builder
|
|
6
|
+
* takes rows. Nothing here reads the chain — every figure is the INDEXED view
|
|
7
|
+
* (the subgraph lags writes), which is why the summary carries `source: "subgraph"`
|
|
8
|
+
* and must never size a transaction.
|
|
9
|
+
*/
|
|
10
|
+
import { LoanStatus } from "../types/loanStatus";
|
|
11
|
+
import type { BorrowerUcdDebtSummary } from "../interfaces/chunks/loan-operations.i";
|
|
12
|
+
/** The subgraph fields a debt summary needs, exactly as the indexer serialises them. */
|
|
13
|
+
export interface BorrowerDebtRow {
|
|
14
|
+
id: string;
|
|
15
|
+
/** Subgraph enum label, e.g. "ACTIVE" — NOT the numeric LoanStatus. */
|
|
16
|
+
status: string;
|
|
17
|
+
/** Wei (18 decimals) as the subgraph's BigInt decimal string. */
|
|
18
|
+
ucdDebt: string;
|
|
19
|
+
}
|
|
20
|
+
/** One page per round trip at The Graph's ceiling; nothing to tune. */
|
|
21
|
+
export declare const BORROWER_DEBT_ROWS_PAGE_SIZE = 1000;
|
|
22
|
+
/** 10 × 1000 = 10_000 positions. Past this the loop THROWS — never a partial total. */
|
|
23
|
+
export declare const BORROWER_DEBT_ROWS_MAX_PAGES = 10;
|
|
24
|
+
export type BorrowerDebtPageFetcher = (skip: number, first: number) => Promise<BorrowerDebtRow[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Page `fetchPage` from skip 0 in `BORROWER_DEBT_ROWS_PAGE_SIZE` steps until a
|
|
27
|
+
* short page. A page failure propagates untouched (the caller wraps it with the
|
|
28
|
+
* cause); the page cap throws rather than returning what was collected so far.
|
|
29
|
+
*/
|
|
30
|
+
export declare function collectBorrowerDebtRows(fetchPage: BorrowerDebtPageFetcher): Promise<BorrowerDebtRow[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Subgraph `Position.status` is the enum LABEL ("ACTIVE"). Convert it explicitly
|
|
33
|
+
* and throw on anything else — the `as LoanStatus` cast elsewhere in the SDK only
|
|
34
|
+
* pretends the string is a number.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseSubgraphLoanStatus(label: unknown): LoanStatus;
|
|
37
|
+
/** Exact 18-decimal rendering with trailing zeros trimmed: "5", "21.93", "0". */
|
|
38
|
+
export declare function weiToHumanUcdString(wei: bigint): string;
|
|
39
|
+
/**
|
|
40
|
+
* Sum every row regardless of status (terminal rows are expected to carry 0; a
|
|
41
|
+
* non-zero terminal row is an indexer defect that should show up in the total,
|
|
42
|
+
* not be filtered away) and histogram the statuses.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildBorrowerUcdDebtSummary(borrower: string, rows: ReadonlyArray<BorrowerDebtRow>, fetchedAt?: number): BorrowerUcdDebtSummary;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gvnrdao/dh-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.339",
|
|
4
4
|
"description": "TypeScript SDK for Diamond Hands Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"sideEffects": false,
|
|
95
95
|
"dependencies": {
|
|
96
96
|
"@gvnrdao/dh-lit-actions": "^0.0.322",
|
|
97
|
-
"@gvnrdao/dh-lit-ops": "^0.0.
|
|
97
|
+
"@gvnrdao/dh-lit-ops": "^0.0.316",
|
|
98
98
|
"@noble/hashes": "^1.5.0",
|
|
99
99
|
"axios": "^1.17.0",
|
|
100
100
|
"bech32": "^2.0.0",
|