@kasufinance/kasu-sdk 2.10.3 → 2.12.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 +28 -1
- package/dist/bundle.cjs.js +752 -59
- package/dist/bundle.esm.js +750 -60
- package/dist/domain/index.d.ts +10 -2
- package/dist/domain/index.js +6 -0
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/strategy-summary.d.ts +47 -0
- package/dist/domain/strategy-summary.js +76 -0
- package/dist/domain/strategy-summary.js.map +1 -0
- package/dist/domain/yield-history.d.ts +122 -0
- package/dist/domain/yield-history.js +95 -0
- package/dist/domain/yield-history.js.map +1 -0
- package/dist/facade/strategies.js +2 -0
- package/dist/facade/strategies.js.map +1 -1
- package/dist/facade/types.d.ts +13 -0
- package/dist/facade/user-portfolio.d.ts +32 -0
- package/dist/facade/user-portfolio.js +34 -0
- package/dist/facade/user-portfolio.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/services/Portfolio/portfolio.d.ts +37 -0
- package/dist/services/Portfolio/portfolio.js +136 -56
- package/dist/services/Portfolio/portfolio.js.map +1 -1
- package/dist/services/Portfolio/queries.js +15 -3
- package/dist/services/Portfolio/queries.js.map +1 -1
- package/dist/services/Portfolio/types.d.ts +8 -0
- package/dist/services/Portfolio/yield-history.d.ts +177 -0
- package/dist/services/Portfolio/yield-history.js +405 -0
- package/dist/services/Portfolio/yield-history.js.map +1 -0
- package/package.json +2 -1
- package/src/domain/index.ts +19 -10
- package/src/domain/strategy-summary.ts +88 -0
- package/src/domain/yield-history.ts +194 -0
- package/src/facade/strategies.ts +2 -0
- package/src/facade/types.ts +13 -0
- package/src/facade/user-portfolio.ts +40 -3
- package/src/index.ts +2 -0
- package/src/services/Portfolio/portfolio.ts +263 -153
- package/src/services/Portfolio/queries.ts +15 -3
- package/src/services/Portfolio/types.ts +10 -0
- package/src/services/Portfolio/yield-history.ts +574 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { YieldHistoryEntry } from '../../domain/yield-history';
|
|
2
|
+
/**
|
|
3
|
+
* Which settled epochs a history covers. Epochs are counted in the chain's
|
|
4
|
+
* numbering (`SystemVariables.currentEpochNumber`). Only SETTLED epochs exist
|
|
5
|
+
* in a history — the newest is `currentEpoch − 1`.
|
|
6
|
+
*
|
|
7
|
+
* - neither field: every settled epoch;
|
|
8
|
+
* - `count` only: the newest `count` settled epochs;
|
|
9
|
+
* - `fromEpoch` only: `fromEpoch` up to the newest settled epoch;
|
|
10
|
+
* - both: `count` epochs starting at `fromEpoch`, capped at the newest settled.
|
|
11
|
+
*/
|
|
12
|
+
export interface YieldHistoryOptions {
|
|
13
|
+
/** First epoch included. A non-negative integer. */
|
|
14
|
+
fromEpoch?: number;
|
|
15
|
+
/** How many epochs. A positive integer. */
|
|
16
|
+
count?: number;
|
|
17
|
+
}
|
|
18
|
+
/** The resolved, inclusive epoch range; `null` when it holds no settled epoch. */
|
|
19
|
+
export interface YieldHistoryWindow {
|
|
20
|
+
fromEpoch: number;
|
|
21
|
+
toEpoch: number;
|
|
22
|
+
}
|
|
23
|
+
/** The subgraph returns at most this many rows per collection per request. */
|
|
24
|
+
export declare const YIELD_HISTORY_PAGE_SIZE = 1000;
|
|
25
|
+
/**
|
|
26
|
+
* A runaway guard, not a working limit: a collection this many pages long
|
|
27
|
+
* (`MAX × PAGE_SIZE` rows for one lender) is a broken response, not a history.
|
|
28
|
+
*/
|
|
29
|
+
export declare const YIELD_HISTORY_MAX_PAGES = 100;
|
|
30
|
+
/**
|
|
31
|
+
* Throws `RangeError` on a malformed `fromEpoch` / `count`. `getYieldHistory`
|
|
32
|
+
* calls it BEFORE any network read.
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateYieldHistoryOptions(options: YieldHistoryOptions): void;
|
|
35
|
+
export declare function resolveYieldHistoryWindow(options: YieldHistoryOptions, currentEpoch: number): YieldHistoryWindow | null;
|
|
36
|
+
/**
|
|
37
|
+
* Round trip 1: the lender's tranche positions and fixed-term locks. Same
|
|
38
|
+
* pool exclusion and the same nested-list size (`$first`) as
|
|
39
|
+
* `lendingPortfolioQuery`, so both read the same lock set.
|
|
40
|
+
*/
|
|
41
|
+
export declare const yieldHistoryPositionsQuery: string;
|
|
42
|
+
/**
|
|
43
|
+
* Round trip 2 onwards: the four per-epoch series, one page of each per
|
|
44
|
+
* request, cursor-paginated by `id`. A series that is exhausted is skipped with
|
|
45
|
+
* `@include`, so a history costs as many requests as its LONGEST series has
|
|
46
|
+
* pages — normally one — never one per epoch.
|
|
47
|
+
*
|
|
48
|
+
* Share snapshots are read up to the window's end with no lower bound: the
|
|
49
|
+
* value AS OF the first epoch may come from an update long before it.
|
|
50
|
+
*/
|
|
51
|
+
export declare const yieldHistoryPageQuery: string;
|
|
52
|
+
export interface YieldHistoryPositionsResult {
|
|
53
|
+
user: {
|
|
54
|
+
lendingPoolUserDetails: {
|
|
55
|
+
lendingPool: {
|
|
56
|
+
id: string;
|
|
57
|
+
};
|
|
58
|
+
lendingPoolTrancheUserDetails: {
|
|
59
|
+
id: string;
|
|
60
|
+
tranche: {
|
|
61
|
+
id: string;
|
|
62
|
+
balance: string;
|
|
63
|
+
shares: string;
|
|
64
|
+
};
|
|
65
|
+
userLendingPoolTrancheFixedTermDepositLocks: {
|
|
66
|
+
id: string;
|
|
67
|
+
epochLockStart: string;
|
|
68
|
+
epochLockEnd: string;
|
|
69
|
+
initialTrancheShares: string;
|
|
70
|
+
}[];
|
|
71
|
+
}[];
|
|
72
|
+
}[];
|
|
73
|
+
} | null;
|
|
74
|
+
}
|
|
75
|
+
/** One share snapshot: the value from `epochId` on, until the next one. */
|
|
76
|
+
export interface ShareUpdateRow {
|
|
77
|
+
id: string;
|
|
78
|
+
epochId: string;
|
|
79
|
+
shareUpdatesIndex: number;
|
|
80
|
+
shares: string;
|
|
81
|
+
}
|
|
82
|
+
export interface InterestRow {
|
|
83
|
+
id: string;
|
|
84
|
+
epochId: string;
|
|
85
|
+
epochInterestAmount: string;
|
|
86
|
+
lendingPoolTranche: {
|
|
87
|
+
id: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface YieldHistoryPageResult {
|
|
91
|
+
interest?: InterestRow[];
|
|
92
|
+
trancheShares?: (ShareUpdateRow & {
|
|
93
|
+
lendingPoolTranche: {
|
|
94
|
+
id: string;
|
|
95
|
+
};
|
|
96
|
+
})[];
|
|
97
|
+
userShares?: (ShareUpdateRow & {
|
|
98
|
+
lendingPoolTrancheUserDetails: {
|
|
99
|
+
id: string;
|
|
100
|
+
};
|
|
101
|
+
})[];
|
|
102
|
+
lockShares?: (ShareUpdateRow & {
|
|
103
|
+
userLendingPoolTrancheFixedTermDepositLock: {
|
|
104
|
+
id: string;
|
|
105
|
+
};
|
|
106
|
+
})[];
|
|
107
|
+
}
|
|
108
|
+
/** Everything `buildYieldHistory` reads, keyed by the subgraph's entity ids. */
|
|
109
|
+
export interface YieldHistoryRead {
|
|
110
|
+
positions: YieldHistoryPositionsResult;
|
|
111
|
+
interest: InterestRow[];
|
|
112
|
+
trancheShares: (ShareUpdateRow & {
|
|
113
|
+
lendingPoolTranche: {
|
|
114
|
+
id: string;
|
|
115
|
+
};
|
|
116
|
+
})[];
|
|
117
|
+
userShares: (ShareUpdateRow & {
|
|
118
|
+
lendingPoolTrancheUserDetails: {
|
|
119
|
+
id: string;
|
|
120
|
+
};
|
|
121
|
+
})[];
|
|
122
|
+
lockShares: (ShareUpdateRow & {
|
|
123
|
+
userLendingPoolTrancheFixedTermDepositLock: {
|
|
124
|
+
id: string;
|
|
125
|
+
};
|
|
126
|
+
})[];
|
|
127
|
+
}
|
|
128
|
+
/** The chain's epoch clock: epoch E ends at `epochZeroStart + (E + 1) × duration`. */
|
|
129
|
+
export interface EpochClock {
|
|
130
|
+
epochZeroStart: number;
|
|
131
|
+
epochDuration: number;
|
|
132
|
+
}
|
|
133
|
+
type PageRequest = (variables: Record<string, unknown>) => Promise<YieldHistoryPageResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Fetch the four series for the window, paginating each by `id` until a short
|
|
136
|
+
* page. Returns the rows and how many requests it took.
|
|
137
|
+
*/
|
|
138
|
+
export declare function fetchYieldHistorySeries(request: PageRequest, ids: {
|
|
139
|
+
tranches: string[];
|
|
140
|
+
userTranches: string[];
|
|
141
|
+
locks: string[];
|
|
142
|
+
}, window: YieldHistoryWindow): Promise<{
|
|
143
|
+
rows: Omit<YieldHistoryRead, 'positions'>;
|
|
144
|
+
requests: number;
|
|
145
|
+
}>;
|
|
146
|
+
/**
|
|
147
|
+
* The snapshot in force at `epoch`: among updates with `epochId ≤ epoch`, the
|
|
148
|
+
* one with the highest `shareUpdatesIndex` — exactly what
|
|
149
|
+
* `lendingPortfolioQuery` selects with `orderBy: shareUpdatesIndex, desc,
|
|
150
|
+
* first: 1, where: { epochId_lt: epoch + 1 }`. `undefined` when none.
|
|
151
|
+
*/
|
|
152
|
+
export declare function sharesAsOf(updates: readonly ShareUpdateRow[], epoch: number): ShareUpdateRow | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Pure: the fetched series → one entry per pool, tranche and settled epoch in
|
|
155
|
+
* which the lender held shares (or a lock earned a top-up). Each entry runs the
|
|
156
|
+
* same `epochTrancheYield` as the portfolio's last-epoch figure, with the same
|
|
157
|
+
* share selection, so the newest entry equals that figure.
|
|
158
|
+
*
|
|
159
|
+
* Sorted by `epochId`, then `poolId`, then `trancheId`.
|
|
160
|
+
*/
|
|
161
|
+
export declare function buildYieldHistory(read: YieldHistoryRead, window: YieldHistoryWindow, clock: EpochClock): YieldHistoryEntry[];
|
|
162
|
+
/**
|
|
163
|
+
* A GraphQL VALIDATION error naming an entity, field or argument this
|
|
164
|
+
* deployment's subgraph does not have. A network error, a timeout or an
|
|
165
|
+
* indexing error is not one.
|
|
166
|
+
*/
|
|
167
|
+
export declare function isMissingEntityError(error: unknown): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* The only failure `getYieldHistory` turns into `[]`: a missing-schema error
|
|
170
|
+
* on a LITE deployment, whose subgraph may predate the entities. On a full
|
|
171
|
+
* deployment the entities are part of the schema, so the same error means a
|
|
172
|
+
* broken query or subgraph and THROWS — an empty chart there would hide it.
|
|
173
|
+
* Everything else (network, timeout, indexing) throws on every deployment, so
|
|
174
|
+
* a consumer can tell "no history here" from "history unavailable".
|
|
175
|
+
*/
|
|
176
|
+
export declare function isEmptyHistoryError(error: unknown, liteDeployment: boolean): boolean;
|
|
177
|
+
export {};
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { gql } from 'graphql-request';
|
|
11
|
+
import { epochTrancheYield, } from '../../domain/yield-history';
|
|
12
|
+
/** The subgraph returns at most this many rows per collection per request. */
|
|
13
|
+
export const YIELD_HISTORY_PAGE_SIZE = 1000;
|
|
14
|
+
/**
|
|
15
|
+
* A runaway guard, not a working limit: a collection this many pages long
|
|
16
|
+
* (`MAX × PAGE_SIZE` rows for one lender) is a broken response, not a history.
|
|
17
|
+
*/
|
|
18
|
+
export const YIELD_HISTORY_MAX_PAGES = 100;
|
|
19
|
+
/**
|
|
20
|
+
* Throws `RangeError` on a malformed `fromEpoch` / `count`. `getYieldHistory`
|
|
21
|
+
* calls it BEFORE any network read.
|
|
22
|
+
*/
|
|
23
|
+
export function validateYieldHistoryOptions(options) {
|
|
24
|
+
const { fromEpoch, count } = options;
|
|
25
|
+
if (fromEpoch !== undefined &&
|
|
26
|
+
(!Number.isSafeInteger(fromEpoch) || fromEpoch < 0)) {
|
|
27
|
+
throw new RangeError(`getYieldHistory: fromEpoch must be a non-negative integer, got ${String(fromEpoch)}`);
|
|
28
|
+
}
|
|
29
|
+
if (count !== undefined && (!Number.isSafeInteger(count) || count < 1)) {
|
|
30
|
+
throw new RangeError(`getYieldHistory: count must be a positive integer, got ${String(count)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function resolveYieldHistoryWindow(options, currentEpoch) {
|
|
34
|
+
validateYieldHistoryOptions(options);
|
|
35
|
+
const { fromEpoch, count } = options;
|
|
36
|
+
const newest = currentEpoch - 1;
|
|
37
|
+
if (newest < 0)
|
|
38
|
+
return null;
|
|
39
|
+
let from;
|
|
40
|
+
let to = newest;
|
|
41
|
+
if (fromEpoch !== undefined) {
|
|
42
|
+
from = fromEpoch;
|
|
43
|
+
if (count !== undefined)
|
|
44
|
+
to = Math.min(newest, fromEpoch + count - 1);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
from = count !== undefined ? Math.max(0, newest - count + 1) : 0;
|
|
48
|
+
}
|
|
49
|
+
return from > to ? null : { fromEpoch: from, toEpoch: to };
|
|
50
|
+
}
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Subgraph reads
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
/**
|
|
55
|
+
* Round trip 1: the lender's tranche positions and fixed-term locks. Same
|
|
56
|
+
* pool exclusion and the same nested-list size (`$first`) as
|
|
57
|
+
* `lendingPortfolioQuery`, so both read the same lock set.
|
|
58
|
+
*/
|
|
59
|
+
export const yieldHistoryPositionsQuery = gql `
|
|
60
|
+
query YieldHistoryPositions(
|
|
61
|
+
$userAddress: ID!
|
|
62
|
+
$unusedPools: [String!]!
|
|
63
|
+
$first: Int!
|
|
64
|
+
) {
|
|
65
|
+
user(id: $userAddress) {
|
|
66
|
+
lendingPoolUserDetails(
|
|
67
|
+
first: $first
|
|
68
|
+
where: { lendingPool_not_in: $unusedPools }
|
|
69
|
+
) {
|
|
70
|
+
lendingPool {
|
|
71
|
+
id
|
|
72
|
+
}
|
|
73
|
+
lendingPoolTrancheUserDetails(first: $first) {
|
|
74
|
+
id
|
|
75
|
+
tranche {
|
|
76
|
+
id
|
|
77
|
+
balance
|
|
78
|
+
shares
|
|
79
|
+
}
|
|
80
|
+
userLendingPoolTrancheFixedTermDepositLocks(first: $first) {
|
|
81
|
+
id
|
|
82
|
+
epochLockStart
|
|
83
|
+
epochLockEnd
|
|
84
|
+
initialTrancheShares
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
/**
|
|
92
|
+
* Round trip 2 onwards: the four per-epoch series, one page of each per
|
|
93
|
+
* request, cursor-paginated by `id`. A series that is exhausted is skipped with
|
|
94
|
+
* `@include`, so a history costs as many requests as its LONGEST series has
|
|
95
|
+
* pages — normally one — never one per epoch.
|
|
96
|
+
*
|
|
97
|
+
* Share snapshots are read up to the window's end with no lower bound: the
|
|
98
|
+
* value AS OF the first epoch may come from an update long before it.
|
|
99
|
+
*/
|
|
100
|
+
export const yieldHistoryPageQuery = gql `
|
|
101
|
+
query YieldHistoryPage(
|
|
102
|
+
$tranches: [String!]!
|
|
103
|
+
$userTranches: [String!]!
|
|
104
|
+
$locks: [String!]!
|
|
105
|
+
$fromEpoch: BigInt!
|
|
106
|
+
$toEpoch: BigInt!
|
|
107
|
+
$interestCursor: ID!
|
|
108
|
+
$trancheSharesCursor: ID!
|
|
109
|
+
$userSharesCursor: ID!
|
|
110
|
+
$lockSharesCursor: ID!
|
|
111
|
+
$withInterest: Boolean!
|
|
112
|
+
$withTrancheShares: Boolean!
|
|
113
|
+
$withUserShares: Boolean!
|
|
114
|
+
$withLockShares: Boolean!
|
|
115
|
+
$first: Int!
|
|
116
|
+
) {
|
|
117
|
+
interest: lendingPoolTrancheEpochInterests(
|
|
118
|
+
first: $first
|
|
119
|
+
orderBy: id
|
|
120
|
+
orderDirection: asc
|
|
121
|
+
where: {
|
|
122
|
+
id_gt: $interestCursor
|
|
123
|
+
lendingPoolTranche_in: $tranches
|
|
124
|
+
epochId_gte: $fromEpoch
|
|
125
|
+
epochId_lte: $toEpoch
|
|
126
|
+
}
|
|
127
|
+
) @include(if: $withInterest) {
|
|
128
|
+
id
|
|
129
|
+
epochId
|
|
130
|
+
epochInterestAmount
|
|
131
|
+
lendingPoolTranche {
|
|
132
|
+
id
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
trancheShares: lendingPoolTrancheShareUpdates(
|
|
136
|
+
first: $first
|
|
137
|
+
orderBy: id
|
|
138
|
+
orderDirection: asc
|
|
139
|
+
where: {
|
|
140
|
+
id_gt: $trancheSharesCursor
|
|
141
|
+
lendingPoolTranche_in: $tranches
|
|
142
|
+
epochId_lte: $toEpoch
|
|
143
|
+
}
|
|
144
|
+
) @include(if: $withTrancheShares) {
|
|
145
|
+
id
|
|
146
|
+
epochId
|
|
147
|
+
shareUpdatesIndex
|
|
148
|
+
shares
|
|
149
|
+
lendingPoolTranche {
|
|
150
|
+
id
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
userShares: lendingPoolTrancheUserEpochSharesUpdates(
|
|
154
|
+
first: $first
|
|
155
|
+
orderBy: id
|
|
156
|
+
orderDirection: asc
|
|
157
|
+
where: {
|
|
158
|
+
id_gt: $userSharesCursor
|
|
159
|
+
lendingPoolTrancheUserDetails_in: $userTranches
|
|
160
|
+
epochId_lte: $toEpoch
|
|
161
|
+
}
|
|
162
|
+
) @include(if: $withUserShares) {
|
|
163
|
+
id
|
|
164
|
+
epochId
|
|
165
|
+
shareUpdatesIndex
|
|
166
|
+
shares
|
|
167
|
+
lendingPoolTrancheUserDetails {
|
|
168
|
+
id
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
lockShares: userLendingPoolTrancheFtdLockShareUpdates(
|
|
172
|
+
first: $first
|
|
173
|
+
orderBy: id
|
|
174
|
+
orderDirection: asc
|
|
175
|
+
where: {
|
|
176
|
+
id_gt: $lockSharesCursor
|
|
177
|
+
userLendingPoolTrancheFixedTermDepositLock_in: $locks
|
|
178
|
+
epochId_lte: $toEpoch
|
|
179
|
+
}
|
|
180
|
+
) @include(if: $withLockShares) {
|
|
181
|
+
id
|
|
182
|
+
epochId
|
|
183
|
+
shareUpdatesIndex
|
|
184
|
+
shares
|
|
185
|
+
userLendingPoolTrancheFixedTermDepositLock {
|
|
186
|
+
id
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
191
|
+
/**
|
|
192
|
+
* Fetch the four series for the window, paginating each by `id` until a short
|
|
193
|
+
* page. Returns the rows and how many requests it took.
|
|
194
|
+
*/
|
|
195
|
+
export function fetchYieldHistorySeries(request, ids, window) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
var _a;
|
|
198
|
+
const rows = {
|
|
199
|
+
interest: [],
|
|
200
|
+
trancheShares: [],
|
|
201
|
+
userShares: [],
|
|
202
|
+
lockShares: [],
|
|
203
|
+
};
|
|
204
|
+
const series = [
|
|
205
|
+
{ key: 'interest', flag: 'withInterest', cursor: 'interestCursor' },
|
|
206
|
+
{
|
|
207
|
+
key: 'trancheShares',
|
|
208
|
+
flag: 'withTrancheShares',
|
|
209
|
+
cursor: 'trancheSharesCursor',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
key: 'userShares',
|
|
213
|
+
flag: 'withUserShares',
|
|
214
|
+
cursor: 'userSharesCursor',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
key: 'lockShares',
|
|
218
|
+
flag: 'withLockShares',
|
|
219
|
+
cursor: 'lockSharesCursor',
|
|
220
|
+
},
|
|
221
|
+
];
|
|
222
|
+
const cursors = {
|
|
223
|
+
interest: '',
|
|
224
|
+
trancheShares: '',
|
|
225
|
+
userShares: '',
|
|
226
|
+
lockShares: '',
|
|
227
|
+
};
|
|
228
|
+
const open = {
|
|
229
|
+
interest: ids.tranches.length > 0,
|
|
230
|
+
trancheShares: ids.tranches.length > 0,
|
|
231
|
+
userShares: ids.userTranches.length > 0,
|
|
232
|
+
lockShares: ids.locks.length > 0,
|
|
233
|
+
};
|
|
234
|
+
let requests = 0;
|
|
235
|
+
while (series.some(({ key }) => open[key])) {
|
|
236
|
+
if (requests >= YIELD_HISTORY_MAX_PAGES) {
|
|
237
|
+
throw new Error(`getYieldHistory: more than ${String(YIELD_HISTORY_MAX_PAGES)} pages for one lender`);
|
|
238
|
+
}
|
|
239
|
+
const variables = {
|
|
240
|
+
tranches: ids.tranches,
|
|
241
|
+
userTranches: ids.userTranches,
|
|
242
|
+
locks: ids.locks,
|
|
243
|
+
fromEpoch: String(window.fromEpoch),
|
|
244
|
+
toEpoch: String(window.toEpoch),
|
|
245
|
+
first: YIELD_HISTORY_PAGE_SIZE,
|
|
246
|
+
};
|
|
247
|
+
for (const { key, flag, cursor } of series) {
|
|
248
|
+
variables[flag] = open[key];
|
|
249
|
+
variables[cursor] = cursors[key];
|
|
250
|
+
}
|
|
251
|
+
const page = yield request(variables);
|
|
252
|
+
requests += 1;
|
|
253
|
+
for (const { key } of series) {
|
|
254
|
+
if (!open[key])
|
|
255
|
+
continue;
|
|
256
|
+
const got = (_a = page[key]) !== null && _a !== void 0 ? _a : [];
|
|
257
|
+
rows[key].push(...got);
|
|
258
|
+
const last = got.at(-1);
|
|
259
|
+
if (got.length < YIELD_HISTORY_PAGE_SIZE || last === undefined) {
|
|
260
|
+
open[key] = false;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (last.id <= cursors[key]) {
|
|
264
|
+
throw new Error(`getYieldHistory: the ${key} cursor did not advance`);
|
|
265
|
+
}
|
|
266
|
+
cursors[key] = last.id;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { rows, requests };
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The snapshot in force at `epoch`: among updates with `epochId ≤ epoch`, the
|
|
274
|
+
* one with the highest `shareUpdatesIndex` — exactly what
|
|
275
|
+
* `lendingPortfolioQuery` selects with `orderBy: shareUpdatesIndex, desc,
|
|
276
|
+
* first: 1, where: { epochId_lt: epoch + 1 }`. `undefined` when none.
|
|
277
|
+
*/
|
|
278
|
+
export function sharesAsOf(updates, epoch) {
|
|
279
|
+
let found;
|
|
280
|
+
for (const update of updates) {
|
|
281
|
+
if (Number(update.epochId) > epoch)
|
|
282
|
+
continue;
|
|
283
|
+
if (!found || update.shareUpdatesIndex > found.shareUpdatesIndex) {
|
|
284
|
+
found = update;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return found;
|
|
288
|
+
}
|
|
289
|
+
function groupBy(rows, key) {
|
|
290
|
+
const map = new Map();
|
|
291
|
+
for (const row of rows) {
|
|
292
|
+
const k = key(row);
|
|
293
|
+
const list = map.get(k);
|
|
294
|
+
if (list)
|
|
295
|
+
list.push(row);
|
|
296
|
+
else
|
|
297
|
+
map.set(k, [row]);
|
|
298
|
+
}
|
|
299
|
+
return map;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Pure: the fetched series → one entry per pool, tranche and settled epoch in
|
|
303
|
+
* which the lender held shares (or a lock earned a top-up). Each entry runs the
|
|
304
|
+
* same `epochTrancheYield` as the portfolio's last-epoch figure, with the same
|
|
305
|
+
* share selection, so the newest entry equals that figure.
|
|
306
|
+
*
|
|
307
|
+
* Sorted by `epochId`, then `poolId`, then `trancheId`.
|
|
308
|
+
*/
|
|
309
|
+
export function buildYieldHistory(read, window, clock) {
|
|
310
|
+
var _a, _b, _c, _d, _e, _f;
|
|
311
|
+
const user = read.positions.user;
|
|
312
|
+
if (!user)
|
|
313
|
+
return [];
|
|
314
|
+
const interestByTranche = groupBy(read.interest, (row) => row.lendingPoolTranche.id);
|
|
315
|
+
const trancheSharesByTranche = groupBy(read.trancheShares, (row) => row.lendingPoolTranche.id);
|
|
316
|
+
const userSharesByPosition = groupBy(read.userShares, (row) => row.lendingPoolTrancheUserDetails.id);
|
|
317
|
+
const lockSharesByLock = groupBy(read.lockShares, (row) => row.userLendingPoolTrancheFixedTermDepositLock.id);
|
|
318
|
+
const entries = [];
|
|
319
|
+
for (const pool of user.lendingPoolUserDetails) {
|
|
320
|
+
for (const position of pool.lendingPoolTrancheUserDetails) {
|
|
321
|
+
const trancheId = position.tranche.id;
|
|
322
|
+
const trancheUpdates = (_a = trancheSharesByTranche.get(trancheId)) !== null && _a !== void 0 ? _a : [];
|
|
323
|
+
const userUpdates = (_b = userSharesByPosition.get(position.id)) !== null && _b !== void 0 ? _b : [];
|
|
324
|
+
const trancheBalanceNow = parseFloat(position.tranche.balance);
|
|
325
|
+
const trancheSharesNow = parseFloat(position.tranche.shares);
|
|
326
|
+
for (const record of (_c = interestByTranche.get(trancheId)) !== null && _c !== void 0 ? _c : []) {
|
|
327
|
+
const epoch = Number(record.epochId);
|
|
328
|
+
if (epoch < window.fromEpoch || epoch > window.toEpoch) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const userSnapshot = sharesAsOf(userUpdates, epoch);
|
|
332
|
+
const userShares = parseFloat((_d = userSnapshot === null || userSnapshot === void 0 ? void 0 : userSnapshot.shares) !== null && _d !== void 0 ? _d : '0');
|
|
333
|
+
const locks = position.userLendingPoolTrancheFixedTermDepositLocks.map((lock) => {
|
|
334
|
+
var _a, _b, _c, _d, _e;
|
|
335
|
+
const lockUpdates = (_a = lockSharesByLock.get(lock.id)) !== null && _a !== void 0 ? _a : [];
|
|
336
|
+
return {
|
|
337
|
+
active: parseFloat(lock.epochLockStart) < epoch &&
|
|
338
|
+
parseFloat(lock.epochLockEnd) >= epoch &&
|
|
339
|
+
userSnapshot !== undefined,
|
|
340
|
+
// No snapshot yet = the lock's opening
|
|
341
|
+
// shares: a lock made after clearing E
|
|
342
|
+
// starts at E but its first update is
|
|
343
|
+
// tagged E + 1, and reading that gap as 0
|
|
344
|
+
// would book its principal as a top-up.
|
|
345
|
+
sharesAtEpoch: parseFloat((_c = (_b = sharesAsOf(lockUpdates, epoch)) === null || _b === void 0 ? void 0 : _b.shares) !== null && _c !== void 0 ? _c : lock.initialTrancheShares),
|
|
346
|
+
sharesBeforeEpoch: parseFloat((_e = (_d = sharesAsOf(lockUpdates, epoch - 1)) === null || _d === void 0 ? void 0 : _d.shares) !== null && _e !== void 0 ? _e : lock.initialTrancheShares),
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
const { total } = epochTrancheYield({
|
|
350
|
+
epochInterest: parseFloat(record.epochInterestAmount),
|
|
351
|
+
userShares,
|
|
352
|
+
trancheShares: parseFloat((_f = (_e = sharesAsOf(trancheUpdates, epoch)) === null || _e === void 0 ? void 0 : _e.shares) !== null && _f !== void 0 ? _f : '0'),
|
|
353
|
+
trancheBalanceNow,
|
|
354
|
+
trancheSharesNow,
|
|
355
|
+
locks,
|
|
356
|
+
});
|
|
357
|
+
// Nothing held and nothing topped up: not part of this
|
|
358
|
+
// lender's history (a new lender's history is empty).
|
|
359
|
+
if (userShares <= 0 && total === 0)
|
|
360
|
+
continue;
|
|
361
|
+
entries.push({
|
|
362
|
+
epochId: epoch,
|
|
363
|
+
epochEnd: clock.epochZeroStart +
|
|
364
|
+
(epoch + 1) * clock.epochDuration,
|
|
365
|
+
poolId: pool.lendingPool.id,
|
|
366
|
+
trancheId,
|
|
367
|
+
netYield: total,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return entries.sort((a, b) => a.epochId - b.epochId ||
|
|
373
|
+
a.poolId.localeCompare(b.poolId) ||
|
|
374
|
+
a.trancheId.localeCompare(b.trancheId));
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* A GraphQL VALIDATION error naming an entity, field or argument this
|
|
378
|
+
* deployment's subgraph does not have. A network error, a timeout or an
|
|
379
|
+
* indexing error is not one.
|
|
380
|
+
*/
|
|
381
|
+
export function isMissingEntityError(error) {
|
|
382
|
+
if (typeof error !== 'object' || error === null)
|
|
383
|
+
return false;
|
|
384
|
+
const response = error.response;
|
|
385
|
+
const errors = response === null || response === void 0 ? void 0 : response.errors;
|
|
386
|
+
if (!Array.isArray(errors) || errors.length === 0)
|
|
387
|
+
return false;
|
|
388
|
+
return errors.every((e) => {
|
|
389
|
+
const message = e === null || e === void 0 ? void 0 : e.message;
|
|
390
|
+
return (typeof message === 'string' &&
|
|
391
|
+
/has no field|cannot query field|unknown (type|field|argument)|no such (type|field)/i.test(message));
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* The only failure `getYieldHistory` turns into `[]`: a missing-schema error
|
|
396
|
+
* on a LITE deployment, whose subgraph may predate the entities. On a full
|
|
397
|
+
* deployment the entities are part of the schema, so the same error means a
|
|
398
|
+
* broken query or subgraph and THROWS — an empty chart there would hide it.
|
|
399
|
+
* Everything else (network, timeout, indexing) throws on every deployment, so
|
|
400
|
+
* a consumer can tell "no history here" from "history unavailable".
|
|
401
|
+
*/
|
|
402
|
+
export function isEmptyHistoryError(error, liteDeployment) {
|
|
403
|
+
return liteDeployment && isMissingEntityError(error);
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=yield-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yield-history.js","sourceRoot":"","sources":["../../../src/services/Portfolio/yield-history.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAEH,iBAAiB,GAEpB,MAAM,4BAA4B,CAAC;AAyBpC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AA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AE,CACL,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;QACrB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;QAChC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAC7C,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,QAAQ,GAAI,KAA6C,CAAC,QAAQ,CAAC;IACzE,MAAM,MAAM,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC;IAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;QAC/B,MAAM,OAAO,GAAI,CAAkC,aAAlC,CAAC,uBAAD,CAAC,CAAmC,OAAO,CAAC;QAC7D,OAAO,CACH,OAAO,OAAO,KAAK,QAAQ;YAC3B,qFAAqF,CAAC,IAAI,CACtF,OAAO,CACV,CACJ,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAAc,EACd,cAAuB;IAEvB,OAAO,cAAc,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kasufinance/kasu-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "TypeScript SDK for the Kasu Finance protocol — pool data, portfolio analytics, and KYC-gated deposits and withdrawals on Base and XDC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kasu",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"build-tc": "typechain --target ethers-v5 --out-dir src/contracts './abis/*.json'",
|
|
49
49
|
"build": "eslint . && tsc --build --force tsconfig.json",
|
|
50
50
|
"prepublishOnly": "npm run build && npm run rollup-build",
|
|
51
|
+
"prepare": "node .githooks/install.cjs",
|
|
51
52
|
"build:watch": "npx tsc -b --force --watch",
|
|
52
53
|
"rollup-build": "rollup -c",
|
|
53
54
|
"lint": "eslint . --fix"
|
package/src/domain/index.ts
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
* reconstructs byte-for-byte to verify a lender's signature. Those are not
|
|
17
17
|
* copy: nobody may reword them, in any language, without a matching backend
|
|
18
18
|
* change, which is exactly why they belong in one place.
|
|
19
|
+
*
|
|
20
|
+
* `pickShortDescription` returns a string but AUTHORS none: it selects and
|
|
21
|
+
* cleans editorial the CMS already holds, and an absent blurb is
|
|
22
|
+
* `undefined`, never a sentence of its own.
|
|
19
23
|
* 2. **Pure.** No network, no clock, no environment. Anything with I/O belongs
|
|
20
24
|
* in `facade/` (see `fetchUnusedPoolIds`).
|
|
21
25
|
*/
|
|
@@ -130,11 +134,7 @@ export {
|
|
|
130
134
|
lastEventTimestamp,
|
|
131
135
|
submissionEvents,
|
|
132
136
|
} from './requests';
|
|
133
|
-
export type {
|
|
134
|
-
RequestKind,
|
|
135
|
-
RequestState,
|
|
136
|
-
RequestStatusCode,
|
|
137
|
-
} from './requests';
|
|
137
|
+
export type { RequestKind, RequestState, RequestStatusCode } from './requests';
|
|
138
138
|
|
|
139
139
|
export { decodeRevert, extractRevertData } from './revert-errors';
|
|
140
140
|
export type { DecodedRevert, RevertFamily } from './revert-errors';
|
|
@@ -163,6 +163,9 @@ export {
|
|
|
163
163
|
} from './sponsored-calls';
|
|
164
164
|
export type { SponsoredCall, SponsoredCallKind } from './sponsored-calls';
|
|
165
165
|
|
|
166
|
+
export { pickShortDescription } from './strategy-summary';
|
|
167
|
+
export type { ShortDescriptionSource } from './strategy-summary';
|
|
168
|
+
|
|
166
169
|
export { getTrancheDisplayName, UPPER_MEZZANINE } from './tranche-display-name';
|
|
167
170
|
|
|
168
171
|
export {
|
|
@@ -176,11 +179,7 @@ export {
|
|
|
176
179
|
trancheHasCapacity,
|
|
177
180
|
trancheRiskRank,
|
|
178
181
|
} from './tranches';
|
|
179
|
-
export type {
|
|
180
|
-
ApyBounds,
|
|
181
|
-
PoolStatus,
|
|
182
|
-
TrancheCapacitySignal,
|
|
183
|
-
} from './tranches';
|
|
182
|
+
export type { ApyBounds, PoolStatus, TrancheCapacitySignal } from './tranches';
|
|
184
183
|
|
|
185
184
|
export {
|
|
186
185
|
classifyWalletFailure,
|
|
@@ -189,6 +188,16 @@ export {
|
|
|
189
188
|
} from './wallet-errors';
|
|
190
189
|
export type { WalletFailure } from './wallet-errors';
|
|
191
190
|
|
|
191
|
+
export { aggregateYieldHistory, epochTrancheYield } from './yield-history';
|
|
192
|
+
export type {
|
|
193
|
+
EpochLockShares,
|
|
194
|
+
EpochTrancheYield,
|
|
195
|
+
EpochTrancheYieldInput,
|
|
196
|
+
YieldHistoryEntry,
|
|
197
|
+
YieldHistoryFilter,
|
|
198
|
+
YieldHistoryPoint,
|
|
199
|
+
} from './yield-history';
|
|
200
|
+
|
|
192
201
|
export {
|
|
193
202
|
accruedInterest,
|
|
194
203
|
dailyInterest,
|