@kasufinance/kasu-sdk 2.11.0 → 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 +11 -1
- package/dist/bundle.cjs.js +674 -59
- package/dist/bundle.esm.js +673 -60
- package/dist/domain/index.d.ts +4 -2
- package/dist/domain/index.js +1 -0
- package/dist/domain/index.js.map +1 -1
- 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/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 +1 -1
- package/src/domain/index.ts +12 -10
- package/src/domain/yield-history.ts +194 -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
package/dist/domain/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export type { ContractListItem, ContractSection, ContractType, ExemptLoanContrac
|
|
|
41
41
|
export { maxNetRateCeiling, pickHighestYieldTranche, poolMaxApy, selectVisiblePools, } from './pools';
|
|
42
42
|
export type { BestTranche } from './pools';
|
|
43
43
|
export { cancelDeadline, countSubmissions, deriveRequestState, firstSubmissionTimestamp, isCycleClosed, lastEventTimestamp, submissionEvents, } from './requests';
|
|
44
|
-
export type { RequestKind, RequestState, RequestStatusCode
|
|
44
|
+
export type { RequestKind, RequestState, RequestStatusCode } from './requests';
|
|
45
45
|
export { decodeRevert, extractRevertData } from './revert-errors';
|
|
46
46
|
export type { DecodedRevert, RevertFamily } from './revert-errors';
|
|
47
47
|
export { CLEARING_WINDOW_SECONDS, computeSettlementWindow, deriveCycleDates, nextCycleBoundary, } from './settlement';
|
|
@@ -52,8 +52,10 @@ export { pickShortDescription } from './strategy-summary';
|
|
|
52
52
|
export type { ShortDescriptionSource } from './strategy-summary';
|
|
53
53
|
export { getTrancheDisplayName, UPPER_MEZZANINE } from './tranche-display-name';
|
|
54
54
|
export { compareTrancheSeniority, derivePoolStatus, MIN_TRANCHE_CAPACITY, netTrancheApyBounds, pickDefaultTrancheId, poolAllTranchesFull, trancheApyBounds, trancheHasCapacity, trancheRiskRank, } from './tranches';
|
|
55
|
-
export type { ApyBounds, PoolStatus, TrancheCapacitySignal
|
|
55
|
+
export type { ApyBounds, PoolStatus, TrancheCapacitySignal } from './tranches';
|
|
56
56
|
export { classifyWalletFailure, isUnpredictableGas, isUserRejected, } from './wallet-errors';
|
|
57
57
|
export type { WalletFailure } from './wallet-errors';
|
|
58
|
+
export { aggregateYieldHistory, epochTrancheYield } from './yield-history';
|
|
59
|
+
export type { EpochLockShares, EpochTrancheYield, EpochTrancheYieldInput, YieldHistoryEntry, YieldHistoryFilter, YieldHistoryPoint, } from './yield-history';
|
|
58
60
|
export { accruedInterest, dailyInterest, projectedAnnualEarnings, SECONDS_PER_WEEK, weeklyInterest, weightedAverageApy, } from './yields';
|
|
59
61
|
export type { InterestSlice, PoolAccrual } from './yields';
|
package/dist/domain/index.js
CHANGED
|
@@ -40,5 +40,6 @@ export { pickShortDescription } from './strategy-summary';
|
|
|
40
40
|
export { getTrancheDisplayName, UPPER_MEZZANINE } from './tranche-display-name';
|
|
41
41
|
export { compareTrancheSeniority, derivePoolStatus, MIN_TRANCHE_CAPACITY, netTrancheApyBounds, pickDefaultTrancheId, poolAllTranchesFull, trancheApyBounds, trancheHasCapacity, trancheRiskRank, } from './tranches';
|
|
42
42
|
export { classifyWalletFailure, isUnpredictableGas, isUserRejected, } from './wallet-errors';
|
|
43
|
+
export { aggregateYieldHistory, epochTrancheYield } from './yield-history';
|
|
43
44
|
export { accruedInterest, dailyInterest, projectedAnnualEarnings, SECONDS_PER_WEEK, weeklyInterest, weightedAverageApy, } from './yields';
|
|
44
45
|
//# sourceMappingURL=index.js.map
|
package/dist/domain/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EACH,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,GAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACH,SAAS,EACT,2BAA2B,EAC3B,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACH,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,GAC5B,MAAM,eAAe,CAAC;AAavB,OAAO,EACH,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EACH,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACH,MAAM,EACN,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,aAAa,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACH,cAAc,EACd,wBAAwB,EACxB,2BAA2B,EAC3B,iCAAiC,EACjC,6BAA6B,EAC7B,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,GACxB,MAAM,iBAAiB,CAAC;AAYzB,OAAO,EACH,iBAAiB,EACjB,uBAAuB,EACvB,UAAU,EACV,kBAAkB,GACrB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACH,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,GACnB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EACH,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,GAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACH,SAAS,EACT,2BAA2B,EAC3B,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACH,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,GAC5B,MAAM,eAAe,CAAC;AAavB,OAAO,EACH,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EACH,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACH,MAAM,EACN,mBAAmB,EACnB,sBAAsB,E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EACvB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACrB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settled interest per cycle (epoch): what a lender was credited at each close,
|
|
3
|
+
* per pool and tranche, and the one formula that turns a tranche's credited
|
|
4
|
+
* interest into one lender's share of it.
|
|
5
|
+
*
|
|
6
|
+
* **The figures are NET, and only net.** `LendingPool._applyTrancheInterest`
|
|
7
|
+
* takes the performance fee off first and emits `InterestApplied` with the
|
|
8
|
+
* lender side only (`interest × (1 − performanceFee)`); a fixed-term top-up
|
|
9
|
+
* (`_applyFixedRateInterests`) is net of the fee the same way. So the figure
|
|
10
|
+
* this module computes from those records IS what the lender was credited —
|
|
11
|
+
* never take the fee off it again. No gross is offered: the subgraph keeps
|
|
12
|
+
* only TODAY's fee, so a historical gross would be a guess.
|
|
13
|
+
*
|
|
14
|
+
* Units: amounts are display units of the DEPLOYMENT'S OWN stable token (USDC
|
|
15
|
+
* on Base and XDC USDC, AUDD on XDC AUDD) — never converted to USD here;
|
|
16
|
+
* shares are display units of tranche shares, as the subgraph's BigDecimals.
|
|
17
|
+
*/
|
|
18
|
+
/** One fixed-term lock inside a tranche position, at one epoch. */
|
|
19
|
+
export interface EpochLockShares {
|
|
20
|
+
/**
|
|
21
|
+
* The lock earns in this epoch: it started BEFORE the epoch, ends at or
|
|
22
|
+
* after it, and the lender has a share snapshot for the tranche at it.
|
|
23
|
+
*/
|
|
24
|
+
active: boolean;
|
|
25
|
+
/** The lock's tranche shares as of the epoch (latest update at or before it). */
|
|
26
|
+
sharesAtEpoch: number;
|
|
27
|
+
/** The lock's tranche shares as of the epoch BEFORE it. */
|
|
28
|
+
sharesBeforeEpoch: number;
|
|
29
|
+
}
|
|
30
|
+
/** Everything one lender's share of one tranche's credited interest needs. */
|
|
31
|
+
export interface EpochTrancheYieldInput {
|
|
32
|
+
/** The tranche's interest credited at this epoch's close (net of the fee). */
|
|
33
|
+
epochInterest: number;
|
|
34
|
+
/** The lender's tranche shares as of the epoch (fixed-term locks included). */
|
|
35
|
+
userShares: number;
|
|
36
|
+
/** The tranche's total shares as of the epoch. */
|
|
37
|
+
trancheShares: number;
|
|
38
|
+
/**
|
|
39
|
+
* The tranche's CURRENT balance and shares: the price a fixed-term top-up
|
|
40
|
+
* (extra shares) is valued at. The subgraph keeps no per-epoch tranche
|
|
41
|
+
* balance, so an older top-up is valued at today's price — a second-order
|
|
42
|
+
* difference, because the top-up is only the fixed rate's excess over the
|
|
43
|
+
* variable one.
|
|
44
|
+
*/
|
|
45
|
+
trancheBalanceNow: number;
|
|
46
|
+
trancheSharesNow: number;
|
|
47
|
+
locks: readonly EpochLockShares[];
|
|
48
|
+
}
|
|
49
|
+
export interface EpochTrancheYield {
|
|
50
|
+
/** `variable + Σ locks` — the lender's whole yield in the tranche. */
|
|
51
|
+
total: number;
|
|
52
|
+
/** The variable residual: the share-weighted base yield minus the locks' part of it. */
|
|
53
|
+
variable: number;
|
|
54
|
+
/** Each lock's yield, in the order of `input.locks`: its base part plus its top-up. */
|
|
55
|
+
locks: number[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The ONE per-epoch formula. `Portfolio.getPortfolioLendingData` runs it for
|
|
59
|
+
* the last settled epoch and `getYieldHistory` for every epoch of a window, so
|
|
60
|
+
* the two figures cannot drift apart.
|
|
61
|
+
*
|
|
62
|
+
* ```
|
|
63
|
+
* base = epochInterest × userShares / trancheShares
|
|
64
|
+
* lockBase = base × lock.sharesBeforeEpoch / userShares (active locks)
|
|
65
|
+
* topUp = (lock.sharesAtEpoch − lock.sharesBeforeEpoch) × trancheBalanceNow / trancheSharesNow
|
|
66
|
+
* variable = base − Σ lockBase
|
|
67
|
+
* total = variable + Σ (lockBase + topUp)
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* A zero denominator contributes 0 (a tranche or a lender with no shares
|
|
71
|
+
* earned nothing at that close), never `NaN`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function epochTrancheYield(input: EpochTrancheYieldInput): EpochTrancheYield;
|
|
74
|
+
/** One lender's settled yield in one tranche at one epoch. */
|
|
75
|
+
export interface YieldHistoryEntry {
|
|
76
|
+
/** The epoch (cycle) number, in the chain's numbering. */
|
|
77
|
+
epochId: number;
|
|
78
|
+
/**
|
|
79
|
+
* When the epoch ended — the next epoch's start — in unix SECONDS (not
|
|
80
|
+
* milliseconds).
|
|
81
|
+
*/
|
|
82
|
+
epochEnd: number;
|
|
83
|
+
/** Lowercased lending pool address. */
|
|
84
|
+
poolId: string;
|
|
85
|
+
/** Lowercased tranche address. */
|
|
86
|
+
trancheId: string;
|
|
87
|
+
/**
|
|
88
|
+
* What the close credited the lender in this tranche, AFTER the
|
|
89
|
+
* performance fee, in display units of the deployment's own stable token
|
|
90
|
+
* (AUDD on XDC AUDD — convert before formatting it as USD).
|
|
91
|
+
*/
|
|
92
|
+
netYield: number;
|
|
93
|
+
}
|
|
94
|
+
/** One epoch's yield summed over the entries an aggregation kept. */
|
|
95
|
+
export interface YieldHistoryPoint {
|
|
96
|
+
/** The epoch (cycle) number. */
|
|
97
|
+
epochId: number;
|
|
98
|
+
/** The epoch's end, in unix SECONDS. */
|
|
99
|
+
epochEnd: number;
|
|
100
|
+
/** Net yield summed, in the deployment's own stable token. */
|
|
101
|
+
netYield: number;
|
|
102
|
+
}
|
|
103
|
+
export interface YieldHistoryFilter {
|
|
104
|
+
/** Keep only this pool (case-insensitive). */
|
|
105
|
+
poolId?: string;
|
|
106
|
+
/** Keep only this tranche (case-insensitive). */
|
|
107
|
+
trancheId?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Pool/tranche entries → one point per epoch, ascending by `epochId`. With no
|
|
111
|
+
* filter it sums every strategy (the Lend tab's bars); with `poolId` it is one
|
|
112
|
+
* strategy (a strategy page's bars).
|
|
113
|
+
*
|
|
114
|
+
* An epoch appears only if a kept entry has it — there is no zero padding, so
|
|
115
|
+
* an empty input (a new lender) is an empty output.
|
|
116
|
+
*
|
|
117
|
+
* For a fixed-term lock holder the bars can sum to slightly MORE than the
|
|
118
|
+
* lender's lifetime interest (up to about 0.2 %): each top-up is valued at the
|
|
119
|
+
* tranche's CURRENT share price, which has grown since. Show "earned to date"
|
|
120
|
+
* from the lifetime figure, never from this sum.
|
|
121
|
+
*/
|
|
122
|
+
export declare function aggregateYieldHistory(entries: readonly YieldHistoryEntry[], filter?: YieldHistoryFilter): YieldHistoryPoint[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settled interest per cycle (epoch): what a lender was credited at each close,
|
|
3
|
+
* per pool and tranche, and the one formula that turns a tranche's credited
|
|
4
|
+
* interest into one lender's share of it.
|
|
5
|
+
*
|
|
6
|
+
* **The figures are NET, and only net.** `LendingPool._applyTrancheInterest`
|
|
7
|
+
* takes the performance fee off first and emits `InterestApplied` with the
|
|
8
|
+
* lender side only (`interest × (1 − performanceFee)`); a fixed-term top-up
|
|
9
|
+
* (`_applyFixedRateInterests`) is net of the fee the same way. So the figure
|
|
10
|
+
* this module computes from those records IS what the lender was credited —
|
|
11
|
+
* never take the fee off it again. No gross is offered: the subgraph keeps
|
|
12
|
+
* only TODAY's fee, so a historical gross would be a guess.
|
|
13
|
+
*
|
|
14
|
+
* Units: amounts are display units of the DEPLOYMENT'S OWN stable token (USDC
|
|
15
|
+
* on Base and XDC USDC, AUDD on XDC AUDD) — never converted to USD here;
|
|
16
|
+
* shares are display units of tranche shares, as the subgraph's BigDecimals.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The ONE per-epoch formula. `Portfolio.getPortfolioLendingData` runs it for
|
|
20
|
+
* the last settled epoch and `getYieldHistory` for every epoch of a window, so
|
|
21
|
+
* the two figures cannot drift apart.
|
|
22
|
+
*
|
|
23
|
+
* ```
|
|
24
|
+
* base = epochInterest × userShares / trancheShares
|
|
25
|
+
* lockBase = base × lock.sharesBeforeEpoch / userShares (active locks)
|
|
26
|
+
* topUp = (lock.sharesAtEpoch − lock.sharesBeforeEpoch) × trancheBalanceNow / trancheSharesNow
|
|
27
|
+
* variable = base − Σ lockBase
|
|
28
|
+
* total = variable + Σ (lockBase + topUp)
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* A zero denominator contributes 0 (a tranche or a lender with no shares
|
|
32
|
+
* earned nothing at that close), never `NaN`.
|
|
33
|
+
*/
|
|
34
|
+
export function epochTrancheYield(input) {
|
|
35
|
+
const base = input.trancheShares === 0
|
|
36
|
+
? 0
|
|
37
|
+
: (input.epochInterest * input.userShares) / input.trancheShares;
|
|
38
|
+
let variable = base;
|
|
39
|
+
const locks = input.locks.map((lock) => {
|
|
40
|
+
if (!lock.active)
|
|
41
|
+
return 0;
|
|
42
|
+
const topUp = input.trancheSharesNow === 0
|
|
43
|
+
? 0
|
|
44
|
+
: ((lock.sharesAtEpoch - lock.sharesBeforeEpoch) *
|
|
45
|
+
input.trancheBalanceNow) /
|
|
46
|
+
input.trancheSharesNow;
|
|
47
|
+
const lockBase = input.userShares === 0
|
|
48
|
+
? 0
|
|
49
|
+
: (base * lock.sharesBeforeEpoch) / input.userShares;
|
|
50
|
+
variable -= lockBase;
|
|
51
|
+
return lockBase + topUp;
|
|
52
|
+
});
|
|
53
|
+
const total = locks.reduce((sum, lockYield) => sum + lockYield, variable);
|
|
54
|
+
return { total, variable, locks };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Pool/tranche entries → one point per epoch, ascending by `epochId`. With no
|
|
58
|
+
* filter it sums every strategy (the Lend tab's bars); with `poolId` it is one
|
|
59
|
+
* strategy (a strategy page's bars).
|
|
60
|
+
*
|
|
61
|
+
* An epoch appears only if a kept entry has it — there is no zero padding, so
|
|
62
|
+
* an empty input (a new lender) is an empty output.
|
|
63
|
+
*
|
|
64
|
+
* For a fixed-term lock holder the bars can sum to slightly MORE than the
|
|
65
|
+
* lender's lifetime interest (up to about 0.2 %): each top-up is valued at the
|
|
66
|
+
* tranche's CURRENT share price, which has grown since. Show "earned to date"
|
|
67
|
+
* from the lifetime figure, never from this sum.
|
|
68
|
+
*/
|
|
69
|
+
export function aggregateYieldHistory(entries, filter = {}) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const poolId = (_a = filter.poolId) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
72
|
+
const trancheId = (_b = filter.trancheId) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
73
|
+
const byEpoch = new Map();
|
|
74
|
+
for (const entry of entries) {
|
|
75
|
+
if (poolId !== undefined && entry.poolId.toLowerCase() !== poolId) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (trancheId !== undefined &&
|
|
79
|
+
entry.trancheId.toLowerCase() !== trancheId) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const point = byEpoch.get(entry.epochId);
|
|
83
|
+
if (point) {
|
|
84
|
+
point.netYield += entry.netYield;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
byEpoch.set(entry.epochId, {
|
|
88
|
+
epochId: entry.epochId,
|
|
89
|
+
epochEnd: entry.epochEnd,
|
|
90
|
+
netYield: entry.netYield,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return [...byEpoch.values()].sort((a, b) => a.epochId - b.epochId);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=yield-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yield-history.js","sourceRoot":"","sources":["../../src/domain/yield-history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA4CH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAA6B;IAE7B,MAAM,IAAI,GACN,KAAK,CAAC,aAAa,KAAK,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,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KAAK,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;YAChE,SAAS;QACb,CAAC;QACD,IACI,SAAS,KAAK,SAAS;YACvB,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,SAAS,EAC7C,CAAC;YACC,SAAS;QACb,CAAC;QAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE,CAAC;YACR,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC;YACjC,SAAS;QACb,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE;YACvB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;SAC3B,CAAC,CAAC;IACP,CAAC;IAED,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Provider } from '@ethersproject/providers';
|
|
2
2
|
import { RequestState } from '../domain/requests';
|
|
3
|
+
import { YieldHistoryEntry } from '../domain/yield-history';
|
|
3
4
|
import { DataService } from '../services/DataService/data-service';
|
|
4
5
|
import { Portfolio } from '../services/Portfolio/portfolio';
|
|
6
|
+
import { YieldHistoryOptions } from '../services/Portfolio/yield-history';
|
|
5
7
|
import { UserRequest } from '../services/UserLending/types';
|
|
6
8
|
import { UserLending } from '../services/UserLending/user-lending';
|
|
7
9
|
import { UserPositions } from './types';
|
|
@@ -29,6 +31,36 @@ export declare class PortfolioFacade {
|
|
|
29
31
|
* SDK was initialised with a Signer but you need a read-only provider).
|
|
30
32
|
*/
|
|
31
33
|
getPositions(userAddress: string, provider?: Provider): Promise<UserPositions>;
|
|
34
|
+
/**
|
|
35
|
+
* The lender's settled yield per cycle, per pool and tranche: what each
|
|
36
|
+
* close credited them, NET of the performance fee (the chain credits it
|
|
37
|
+
* net), in display units of the deployment's own stable token (AUDD on
|
|
38
|
+
* XDC AUDD). `epochEnd` is unix seconds. Net only — no gross is offered.
|
|
39
|
+
*
|
|
40
|
+
* Validates `options` before any read (`RangeError` on a malformed one).
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const entries = await kasu.portfolio.getYieldHistory('0xUser...', { count: 52 });
|
|
44
|
+
* const allStrategies = aggregateYieldHistory(entries);
|
|
45
|
+
* const oneStrategy = aggregateYieldHistory(entries, { poolId });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* `getPositions`' `totalYieldEarningsLastEpoch` for a pool equals that
|
|
49
|
+
* pool's bar for the epoch of its most recently APPLIED interest — which
|
|
50
|
+
* is older than the last cycle for a pool that has not cleared since (the
|
|
51
|
+
* bar carries that older `epochId`). A lender who held nothing at that
|
|
52
|
+
* epoch has no bar there and a figure of 0; their newest bar is from
|
|
53
|
+
* when they last held shares.
|
|
54
|
+
*
|
|
55
|
+
* For a fixed-term lock holder the bars can sum to slightly more than the
|
|
56
|
+
* lifetime interest (up to about 0.2 %), because each top-up is valued at
|
|
57
|
+
* today's share price — show "earned to date" from the lifetime figure,
|
|
58
|
+
* never from the sum of the bars.
|
|
59
|
+
*
|
|
60
|
+
* `[]` for a lender with no history, and on a LITE deployment whose
|
|
61
|
+
* subgraph lacks the entities; on a full deployment that error throws.
|
|
62
|
+
*/
|
|
63
|
+
getYieldHistory(userAddress: string, options?: YieldHistoryOptions): Promise<YieldHistoryEntry[]>;
|
|
32
64
|
/**
|
|
33
65
|
* Fetch a user's full transaction history (deposits, withdrawals, cancellations).
|
|
34
66
|
*/
|
|
@@ -41,6 +41,40 @@ export class PortfolioFacade {
|
|
|
41
41
|
return { pools, summary };
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The lender's settled yield per cycle, per pool and tranche: what each
|
|
46
|
+
* close credited them, NET of the performance fee (the chain credits it
|
|
47
|
+
* net), in display units of the deployment's own stable token (AUDD on
|
|
48
|
+
* XDC AUDD). `epochEnd` is unix seconds. Net only — no gross is offered.
|
|
49
|
+
*
|
|
50
|
+
* Validates `options` before any read (`RangeError` on a malformed one).
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const entries = await kasu.portfolio.getYieldHistory('0xUser...', { count: 52 });
|
|
54
|
+
* const allStrategies = aggregateYieldHistory(entries);
|
|
55
|
+
* const oneStrategy = aggregateYieldHistory(entries, { poolId });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* `getPositions`' `totalYieldEarningsLastEpoch` for a pool equals that
|
|
59
|
+
* pool's bar for the epoch of its most recently APPLIED interest — which
|
|
60
|
+
* is older than the last cycle for a pool that has not cleared since (the
|
|
61
|
+
* bar carries that older `epochId`). A lender who held nothing at that
|
|
62
|
+
* epoch has no bar there and a figure of 0; their newest bar is from
|
|
63
|
+
* when they last held shares.
|
|
64
|
+
*
|
|
65
|
+
* For a fixed-term lock holder the bars can sum to slightly more than the
|
|
66
|
+
* lifetime interest (up to about 0.2 %), because each top-up is valued at
|
|
67
|
+
* today's share price — show "earned to date" from the lifetime figure,
|
|
68
|
+
* never from the sum of the bars.
|
|
69
|
+
*
|
|
70
|
+
* `[]` for a lender with no history, and on a LITE deployment whose
|
|
71
|
+
* subgraph lacks the entities; on a full deployment that error throws.
|
|
72
|
+
*/
|
|
73
|
+
getYieldHistory(userAddress, options) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return yield this._portfolio.getYieldHistory(userAddress, options);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
44
78
|
/**
|
|
45
79
|
* Fetch a user's full transaction history (deposits, withdrawals, cancellations).
|
|
46
80
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-portfolio.js","sourceRoot":"","sources":["../../src/facade/user-portfolio.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"user-portfolio.js","sourceRoot":"","sources":["../../src/facade/user-portfolio.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,oBAAoB,CAAC;AAUtE;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACxB,YACY,YAAyB,EACzB,YAAyB,EACzB,UAAqB;QAFrB,iBAAY,GAAZ,YAAY,CAAa;QACzB,iBAAY,GAAZ,YAAY,CAAa;QACzB,eAAU,GAAV,UAAU,CAAW;IAC9B,CAAC;IAEJ;;;;;;;;;;;OAWG;IACG,YAAY,CACd,WAAmB,EACnB,QAAmB;;YAEnB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;YAE/D,MAAM,aAAa,GACf,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YAE1D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,uBAAuB,CACvD,WAAW,EACX,aAAa,EACb,YAAY,EACZ,QAAQ,CACX,CAAC;YAEF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAmB,CACrD,WAAW,EACX,KAAK,EACL,YAAY,CACf,CAAC;YAEF,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC9B,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,eAAe,CACjB,WAAmB,EACnB,OAA6B;;YAE7B,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACvE,CAAC;KAAA;IAED;;OAEG;IACG,qBAAqB,CACvB,WAA0B;;YAE1B,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;YAC/D,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAC1C,WAAW,EACX,YAAY,CACf,CAAC;QACN,CAAC;KAAA;IAED;;;;;;;;;;;;;;;OAeG;IACG,gBAAgB,CAClB,WAA0B;;YAE1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;YAC/D,OAAO,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAC5C,CAAC;KAAA;CACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { SdkConfig } from './sdk-config';
|
|
|
4
4
|
export type { PoolOverview, TrancheData, LendingTotals, PoolRepayment, RiskManagement, PoolDelegateProfileAndHistory, PoolTranche, PoolCreditMetrics, BadAndDoubtfulDebts, FinancialReportingDocuments, } from './services/DataService/types';
|
|
5
5
|
export type { UserRequest, UserRequestEvent, UserTrancheBalance, UserPoolBalance, UserApyBonus, PortfolioUserTrancheBalance, } from './services/UserLending/types';
|
|
6
6
|
export type { PortfolioSummary, PortfolioLendingPool, PortfolioTranche, PortfolioRewards, PortfolioTrancheDepositDetails, } from './services/Portfolio/types';
|
|
7
|
+
export type { YieldHistoryOptions } from './services/Portfolio/yield-history';
|
|
7
8
|
export type { UserLock, UserBonusData, LockPeriod, GQLGetLockingPeriods, SystemVariables, } from './services/Locking/types';
|
|
8
9
|
export type { PoolOverviewDirectus, PlatformOverviewDirectus, } from './services/DataService/directus-types';
|
|
9
10
|
export { NO_DIRECTUS_URL_MESSAGE } from './services/DataService/directus-client';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAkDzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,8EAA8E;AAC9E,+CAA+C;AAC/C,8EAA8E;AAC9E,cAAc,UAAU,CAAC;AAEzB,8EAA8E;AAC9E,6EAA6E;AAC7E,uDAAuD;AACvD,8EAA8E;AAC9E,cAAc,UAAU,CAAC;AAEzB,8EAA8E;AAC9E,6EAA6E;AAC7E,uEAAuE;AACvE,wDAAwD;AACxD,8EAA8E;AAC9E,cAAc,SAAS,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Provider } from '@ethersproject/providers';
|
|
2
2
|
import { BigNumber, Signer } from 'ethers';
|
|
3
|
+
import { YieldHistoryEntry } from '../../domain/yield-history';
|
|
3
4
|
import { SdkConfig } from '../../sdk-config';
|
|
4
5
|
import { TrancheConfigurationSubgraphResult, TrancheSubgraphResult } from '../DataService/subgraph-types';
|
|
5
6
|
import { PoolOverview } from '../DataService/types';
|
|
6
7
|
import { LockingSummarySubgraphResult, SystemVariables } from '../Locking/types';
|
|
7
8
|
import { PortfolioLendingPool, PortfolioRewards, PortfolioSummary, UserLendingPoolTrancheFixedTermDepositLock } from './types';
|
|
9
|
+
import { YieldHistoryOptions } from './yield-history';
|
|
8
10
|
export declare class Portfolio {
|
|
9
11
|
private _kasuConfig;
|
|
10
12
|
private _lockingService;
|
|
@@ -56,6 +58,41 @@ export declare class Portfolio {
|
|
|
56
58
|
getUserNfts(userAddress: string): Promise<number[]>;
|
|
57
59
|
getPortfolioSummary(userAddress: string, portfolioLendingPools: PortfolioLendingPool[], currentEpoch: string): Promise<PortfolioSummary>;
|
|
58
60
|
getPortfolioLendingData(userAddress: string, poolOverviews: PoolOverview[], currentEpoch: string, provider?: Provider): Promise<PortfolioLendingPool[]>;
|
|
61
|
+
/**
|
|
62
|
+
* The lender's settled yield per cycle (epoch), per pool and tranche —
|
|
63
|
+
* what the chain credited at each close, NET of the performance fee
|
|
64
|
+
* (`domain/yield-history.ts`), in the deployment's own stable token. Each
|
|
65
|
+
* entry runs the same `epochTrancheYield` as `getPortfolioLendingData`'s
|
|
66
|
+
* last-epoch figures: a tranche's `yieldEarnings.lastEpoch` plus its
|
|
67
|
+
* locks' equals its entry for the epoch of the tranche's most recently
|
|
68
|
+
* APPLIED interest (older than the last cycle for a pool that has not
|
|
69
|
+
* cleared since; no entry, and a figure of 0, when the lender held
|
|
70
|
+
* nothing at that epoch).
|
|
71
|
+
*
|
|
72
|
+
* Sum entries with `aggregateYieldHistory` (all strategies, or one with
|
|
73
|
+
* `{ poolId }`). Only epochs in which the lender held shares appear — a
|
|
74
|
+
* new lender gets `[]`. Pools in `UNUSED_LENDING_POOL_IDS` are left out,
|
|
75
|
+
* as in `lendingPortfolioQuery`; Directus enablement is NOT applied.
|
|
76
|
+
*
|
|
77
|
+
* Cost: three parallel `SystemVariables` reads and the positions query in
|
|
78
|
+
* one round, then one subgraph request per page of the longest series
|
|
79
|
+
* (1000 rows a page) — normally two subgraph round trips in all, never one
|
|
80
|
+
* per epoch.
|
|
81
|
+
*
|
|
82
|
+
* On a LITE deployment, a subgraph that lacks the entities (a validation
|
|
83
|
+
* error naming them) yields `[]`; on a full deployment that error throws,
|
|
84
|
+
* like every other failure (`isEmptyHistoryError`).
|
|
85
|
+
*
|
|
86
|
+
* @throws RangeError on a malformed `fromEpoch` / `count`, before any
|
|
87
|
+
* network read.
|
|
88
|
+
*/
|
|
89
|
+
getYieldHistory(userAddress: string, options?: YieldHistoryOptions): Promise<YieldHistoryEntry[]>;
|
|
90
|
+
/**
|
|
91
|
+
* A money figure as a plain decimal string. Below a millionth of a token
|
|
92
|
+
* (the stable asset's own precision) is float noise, never money, so it
|
|
93
|
+
* is `'0'` — not `'1e-7'`, which `parseUnits` rejects, nor `'-3e-12'`. A
|
|
94
|
+
* small negative remainder (above −0.0001) is `'0'` as well.
|
|
95
|
+
*/
|
|
59
96
|
precisionToString(val: number): string;
|
|
60
97
|
calculateFixedTermDepositEarnings(fixedTermDepositLock: UserLendingPoolTrancheFixedTermDepositLock, totalTrancheBalance: string, totalTrancheShares: string): number;
|
|
61
98
|
}
|