@kasufinance/kasu-sdk 2.14.0 → 2.16.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 +45 -5
- package/dist/bundle.cjs.js +1484 -228
- package/dist/bundle.esm.js +1476 -229
- package/dist/domain/index.d.ts +6 -1
- package/dist/domain/index.js +6 -2
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/loan-contract.d.ts +16 -5
- package/dist/domain/loan-contract.js +16 -5
- package/dist/domain/loan-contract.js.map +1 -1
- package/dist/domain/pool-tvl.js +179 -0
- package/dist/domain/pool-tvl.js.map +1 -1
- package/dist/domain/requests.js +29 -19
- package/dist/domain/requests.js.map +1 -1
- package/dist/domain/strategy-details.d.ts +262 -0
- package/dist/domain/strategy-details.js +375 -0
- package/dist/domain/strategy-details.js.map +1 -0
- package/dist/domain/yield-history.d.ts +25 -1
- package/dist/domain/yield-history.js +41 -11
- package/dist/domain/yield-history.js.map +1 -1
- package/dist/facade/index.d.ts +1 -1
- package/dist/facade/index.js +2 -0
- package/dist/facade/index.js.map +1 -1
- package/dist/facade/strategies.d.ts +85 -3
- package/dist/facade/strategies.js +182 -6
- package/dist/facade/strategies.js.map +1 -1
- package/dist/facade/strategy-deployments.js +97 -0
- package/dist/facade/strategy-deployments.js.map +1 -0
- package/dist/facade/types.d.ts +82 -0
- package/dist/flows/deposit-flow.d.ts +19 -5
- package/dist/flows/deposit-flow.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/DataService/data-service.js +80 -9
- package/dist/services/DataService/data-service.js.map +1 -1
- package/dist/services/DataService/tvl-history.js +89 -0
- package/dist/services/DataService/tvl-history.js.map +1 -1
- package/dist/services/Portfolio/portfolio.d.ts +54 -1
- package/dist/services/Portfolio/portfolio.js +357 -80
- package/dist/services/Portfolio/portfolio.js.map +1 -1
- package/dist/services/Portfolio/queries.d.ts +16 -0
- package/dist/services/Portfolio/queries.js +119 -2
- package/dist/services/Portfolio/queries.js.map +1 -1
- package/dist/services/Portfolio/types.d.ts +94 -6
- package/dist/services/Portfolio/yield-history.d.ts +148 -10
- package/dist/services/Portfolio/yield-history.js +241 -31
- package/dist/services/Portfolio/yield-history.js.map +1 -1
- package/dist/services/UserLending/queries.js +2 -7
- package/dist/services/UserLending/queries.js.map +1 -1
- package/dist/services/UserLending/subgraph-types.js.map +1 -1
- package/dist/services/UserLending/types.js.map +1 -1
- package/dist/services/UserLending/user-lending.d.ts +16 -0
- package/dist/services/UserLending/user-lending.js +96 -16
- package/dist/services/UserLending/user-lending.js.map +1 -1
- package/dist/services/shared.d.ts +7 -0
- package/dist/services/shared.js +48 -0
- package/dist/services/shared.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/index.ts +27 -1
- package/src/domain/loan-contract.ts +16 -5
- package/src/domain/strategy-details.ts +528 -0
- package/src/domain/yield-history.ts +47 -11
- package/src/facade/index.ts +3 -0
- package/src/facade/strategies.ts +205 -10
- package/src/facade/types.ts +85 -0
- package/src/flows/deposit-flow.ts +19 -5
- package/src/services/Portfolio/portfolio.ts +559 -126
- package/src/services/Portfolio/queries.ts +119 -2
- package/src/services/Portfolio/types.ts +91 -6
- package/src/services/Portfolio/yield-history.ts +405 -56
- package/src/services/UserLending/user-lending.ts +46 -0
- package/src/services/shared.ts +48 -0
|
@@ -61,20 +61,47 @@ export const lastEpochQuery = gql`
|
|
|
61
61
|
}
|
|
62
62
|
`;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* The portfolio read. Its last-epoch figures pair each tranche's newest
|
|
66
|
+
* interest (epoch E) with the shares in force when clearing E applied it —
|
|
67
|
+
* the selection `getYieldHistory` makes (`positionEpochYield`). For that it
|
|
68
|
+
* reads, per lender and tranche, the newest share snapshot tagged before
|
|
69
|
+
* `$recentEpoch` and EVERY snapshot tagged from it on (with their times), and,
|
|
70
|
+
* for the listed pools (`$poolIds`) and tranches (`$trancheIds`), the
|
|
71
|
+
* clearings and share exits of those recent epochs. `$recentEpoch` is six
|
|
72
|
+
* epochs back (`RECENT_PAIRING_EPOCHS`); a newest interest older than that (a
|
|
73
|
+
* pool that clears rarely) is priced from a history read of its own. Lock
|
|
74
|
+
* snapshots are read the same way from one epoch further back
|
|
75
|
+
* (`$lockRecentEpoch`), since a top-up compares E with E − 1. Every list read
|
|
76
|
+
* with `$first` must come back SHORT of it — a full one is refused, never
|
|
77
|
+
* used truncated. `_meta` is the block the answer describes: the chain is
|
|
78
|
+
* read at that same block.
|
|
79
|
+
*/
|
|
64
80
|
export const lendingPortfolioQuery = gql`
|
|
65
81
|
query LastEpochQuery(
|
|
66
82
|
$userAddress: ID!
|
|
67
83
|
$epochId: BigInt!
|
|
68
84
|
$lastEpochId: BigInt!
|
|
85
|
+
$recentEpoch: BigInt!
|
|
86
|
+
$lockRecentEpoch: BigInt!
|
|
69
87
|
$unusedPools: [String!]!
|
|
88
|
+
$poolIds: [String!]!
|
|
89
|
+
$trancheIds: [String!]!
|
|
70
90
|
$first: Int!
|
|
71
91
|
) {
|
|
92
|
+
_meta {
|
|
93
|
+
block {
|
|
94
|
+
number
|
|
95
|
+
}
|
|
96
|
+
}
|
|
72
97
|
user(id: $userAddress) {
|
|
73
98
|
lendingPoolUserDetails(
|
|
74
99
|
first: $first
|
|
75
100
|
where: { lendingPool_not_in: $unusedPools }
|
|
76
101
|
) {
|
|
77
102
|
id
|
|
103
|
+
totalAcceptedDeposits
|
|
104
|
+
totalAcceptedWithdrawnAmount
|
|
78
105
|
lendingPool {
|
|
79
106
|
id
|
|
80
107
|
name
|
|
@@ -84,16 +111,34 @@ export const lendingPortfolioQuery = gql`
|
|
|
84
111
|
}
|
|
85
112
|
}
|
|
86
113
|
lendingPoolTrancheUserDetails(first: $first) {
|
|
114
|
+
id
|
|
87
115
|
shares
|
|
116
|
+
totalAcceptedDeposits
|
|
117
|
+
totalAcceptedWithdrawnAmount
|
|
88
118
|
lendingPoolTrancheUserEpochSharesUpdates(
|
|
89
119
|
orderDirection: desc
|
|
90
120
|
orderBy: shareUpdatesIndex
|
|
91
|
-
where: { epochId_lt: $
|
|
121
|
+
where: { epochId_lt: $recentEpoch }
|
|
92
122
|
first: 1
|
|
93
123
|
) {
|
|
124
|
+
epochId
|
|
125
|
+
shareUpdatesIndex
|
|
94
126
|
shares
|
|
127
|
+
timestamp
|
|
128
|
+
}
|
|
129
|
+
recentUserShareUpdates: lendingPoolTrancheUserEpochSharesUpdates(
|
|
130
|
+
orderDirection: desc
|
|
131
|
+
orderBy: shareUpdatesIndex
|
|
132
|
+
where: { epochId_gte: $recentEpoch }
|
|
133
|
+
first: $first
|
|
134
|
+
) {
|
|
135
|
+
epochId
|
|
136
|
+
shareUpdatesIndex
|
|
137
|
+
shares
|
|
138
|
+
timestamp
|
|
95
139
|
}
|
|
96
140
|
userLendingPoolTrancheFixedTermDepositLocks(first: $first) {
|
|
141
|
+
id
|
|
97
142
|
isLocked
|
|
98
143
|
unlockAmount
|
|
99
144
|
initialAmount
|
|
@@ -125,6 +170,26 @@ export const lendingPortfolioQuery = gql`
|
|
|
125
170
|
) {
|
|
126
171
|
shares
|
|
127
172
|
}
|
|
173
|
+
lockSharesBase: userLendingPoolTrancheFixedTermDepositLockShareUpdate(
|
|
174
|
+
orderBy: shareUpdatesIndex
|
|
175
|
+
orderDirection: desc
|
|
176
|
+
first: 1
|
|
177
|
+
where: { epochId_lt: $lockRecentEpoch }
|
|
178
|
+
) {
|
|
179
|
+
epochId
|
|
180
|
+
shareUpdatesIndex
|
|
181
|
+
shares
|
|
182
|
+
}
|
|
183
|
+
lockSharesRecent: userLendingPoolTrancheFixedTermDepositLockShareUpdate(
|
|
184
|
+
orderBy: shareUpdatesIndex
|
|
185
|
+
orderDirection: desc
|
|
186
|
+
first: $first
|
|
187
|
+
where: { epochId_gte: $lockRecentEpoch }
|
|
188
|
+
) {
|
|
189
|
+
epochId
|
|
190
|
+
shareUpdatesIndex
|
|
191
|
+
shares
|
|
192
|
+
}
|
|
128
193
|
}
|
|
129
194
|
tranche {
|
|
130
195
|
id
|
|
@@ -134,9 +199,23 @@ export const lendingPortfolioQuery = gql`
|
|
|
134
199
|
first: 1
|
|
135
200
|
orderBy: shareUpdatesIndex
|
|
136
201
|
orderDirection: desc
|
|
137
|
-
where: { epochId_lt: $
|
|
202
|
+
where: { epochId_lt: $recentEpoch }
|
|
138
203
|
) {
|
|
204
|
+
epochId
|
|
205
|
+
shareUpdatesIndex
|
|
139
206
|
shares
|
|
207
|
+
timestamp
|
|
208
|
+
}
|
|
209
|
+
recentTrancheShareUpdates: lendingPoolTrancheShareUpdates(
|
|
210
|
+
first: $first
|
|
211
|
+
orderBy: shareUpdatesIndex
|
|
212
|
+
orderDirection: desc
|
|
213
|
+
where: { epochId_gte: $recentEpoch }
|
|
214
|
+
) {
|
|
215
|
+
epochId
|
|
216
|
+
shareUpdatesIndex
|
|
217
|
+
shares
|
|
218
|
+
timestamp
|
|
140
219
|
}
|
|
141
220
|
lendingPoolTrancheEpochInterest(
|
|
142
221
|
first: 1
|
|
@@ -144,12 +223,50 @@ export const lendingPortfolioQuery = gql`
|
|
|
144
223
|
orderDirection: desc
|
|
145
224
|
where: { epochId_lt: $epochId }
|
|
146
225
|
) {
|
|
226
|
+
epochId
|
|
147
227
|
epochInterestAmount
|
|
148
228
|
}
|
|
149
229
|
}
|
|
150
230
|
}
|
|
151
231
|
}
|
|
152
232
|
}
|
|
233
|
+
lendingPoolClearings(
|
|
234
|
+
first: $first
|
|
235
|
+
orderBy: id
|
|
236
|
+
orderDirection: asc
|
|
237
|
+
where: {
|
|
238
|
+
lendingPool_in: $poolIds
|
|
239
|
+
epochId_gte: $recentEpoch
|
|
240
|
+
epochId_lt: $epochId
|
|
241
|
+
}
|
|
242
|
+
) {
|
|
243
|
+
id
|
|
244
|
+
epochId
|
|
245
|
+
startTimestamp
|
|
246
|
+
lendingPool {
|
|
247
|
+
id
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
recentWithdrawalsAccepted: userRequestEvents(
|
|
251
|
+
first: $first
|
|
252
|
+
orderBy: id
|
|
253
|
+
orderDirection: asc
|
|
254
|
+
where: {
|
|
255
|
+
type_in: [WithdrawalAccepted, ImmediateWithdrawalExecuted]
|
|
256
|
+
tranche_in: $trancheIds
|
|
257
|
+
epochId_gte: $recentEpoch
|
|
258
|
+
epochId_lt: $epochId
|
|
259
|
+
}
|
|
260
|
+
) {
|
|
261
|
+
id
|
|
262
|
+
type
|
|
263
|
+
epochId
|
|
264
|
+
createdOn
|
|
265
|
+
sharesAmount
|
|
266
|
+
tranche {
|
|
267
|
+
id
|
|
268
|
+
}
|
|
269
|
+
}
|
|
153
270
|
userRequests(
|
|
154
271
|
first: $first
|
|
155
272
|
where: {
|
|
@@ -53,6 +53,12 @@ export interface PortfolioTrancheDepositDetails {
|
|
|
53
53
|
}
|
|
54
54
|
export interface PortfolioTranche extends TrancheData {
|
|
55
55
|
investedAmount: string;
|
|
56
|
+
/**
|
|
57
|
+
* Set when `investedAmount` was raised to 0: the locked amount exceeded
|
|
58
|
+
* the tranche balance, which only a position the subgraph ledger cannot
|
|
59
|
+
* describe produces (see `PortfolioLendingPool.ledgerMismatch`).
|
|
60
|
+
*/
|
|
61
|
+
investedAmountFloored?: true;
|
|
56
62
|
yieldEarnings: {
|
|
57
63
|
lastEpoch: string;
|
|
58
64
|
lifetime: string;
|
|
@@ -77,8 +83,36 @@ export interface PortfolioTranche extends TrancheData {
|
|
|
77
83
|
depositDetails: PortfolioTrancheDepositDetails[];
|
|
78
84
|
}[];
|
|
79
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The subgraph ledger and the chain disagreed about the lender's balance in
|
|
88
|
+
* a pool AT THE SAME BLOCK — shares moved to or from the wallet outside a
|
|
89
|
+
* deposit or withdrawal, or a lock whose recorded shares were lost. Balances
|
|
90
|
+
* then come from the chain; display units of the stable token.
|
|
91
|
+
*/
|
|
92
|
+
export interface LedgerMismatch {
|
|
93
|
+
/**
|
|
94
|
+
* `ledger-exceeds-chain`: the ledger credits shares the wallet does not
|
|
95
|
+
* hold — the pool's last-cycle figures are withheld (0), and
|
|
96
|
+
* `getYieldHistory` leaves the pool out. `chain-exceeds-ledger`: the
|
|
97
|
+
* wallet holds shares the ledger never credited — its figures cover only
|
|
98
|
+
* the ledger's shares.
|
|
99
|
+
*/
|
|
100
|
+
kind: 'ledger-exceeds-chain' | 'chain-exceeds-ledger';
|
|
101
|
+
ledgerBalance: string;
|
|
102
|
+
chainBalance: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
80
105
|
export interface PortfolioLendingPool extends Omit<PoolOverview, 'tranches'> {
|
|
81
106
|
totalInvestedAmount: string;
|
|
107
|
+
/** Present only when ledger and chain disagree (see `LedgerMismatch`). */
|
|
108
|
+
ledgerMismatch?: LedgerMismatch;
|
|
109
|
+
/**
|
|
110
|
+
* `false` only when the chain could not be read at the subgraph's block
|
|
111
|
+
* (the node had pruned it, or not reached it) and `latest` was read
|
|
112
|
+
* instead: the balances are the chain's now, and ledger and chain were
|
|
113
|
+
* NOT compared, so no `ledgerMismatch` can be reported. Absent otherwise.
|
|
114
|
+
*/
|
|
115
|
+
chainPinned?: false;
|
|
82
116
|
totalYieldEarningsLastEpoch: string;
|
|
83
117
|
totalYieldEarningsLifetime: string;
|
|
84
118
|
isActive: boolean;
|
|
@@ -89,7 +123,16 @@ export interface LendingPortfolioData {
|
|
|
89
123
|
lendingPools: PortfolioLendingPool[];
|
|
90
124
|
}
|
|
91
125
|
|
|
126
|
+
/** A lock share snapshot as the portfolio query reads it. */
|
|
127
|
+
export interface LockShareSnapshot {
|
|
128
|
+
epochId: string;
|
|
129
|
+
shareUpdatesIndex: number;
|
|
130
|
+
shares: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
92
133
|
export interface UserLendingPoolTrancheFixedTermDepositLock {
|
|
134
|
+
/** `{lendingPool}-{lockId}`; read by `lendingPortfolioQuery`. */
|
|
135
|
+
id?: string;
|
|
93
136
|
isLocked: boolean;
|
|
94
137
|
lockId: string;
|
|
95
138
|
createdOn: string;
|
|
@@ -120,6 +163,13 @@ export interface UserLendingPoolTrancheFixedTermDepositLock {
|
|
|
120
163
|
shares: string;
|
|
121
164
|
}[]
|
|
122
165
|
| undefined;
|
|
166
|
+
/**
|
|
167
|
+
* The newest lock snapshot tagged before `$lockRecentEpoch`, and every one
|
|
168
|
+
* tagged from it on: the candidates `getPortfolioLendingData` pairs a
|
|
169
|
+
* recent interest's epoch with. `lendingPortfolioQuery` responses only.
|
|
170
|
+
*/
|
|
171
|
+
lockSharesBase?: LockShareSnapshot[] | undefined;
|
|
172
|
+
lockSharesRecent?: LockShareSnapshot[] | undefined;
|
|
123
173
|
}
|
|
124
174
|
|
|
125
175
|
export interface LastEpochQueryResult {
|
|
@@ -169,10 +219,23 @@ export interface LastEpochQueryResult {
|
|
|
169
219
|
} | null;
|
|
170
220
|
}
|
|
171
221
|
|
|
222
|
+
/** A tranche or lender share snapshot as the portfolio query reads it. */
|
|
223
|
+
export interface PortfolioShareSnapshot {
|
|
224
|
+
epochId: string;
|
|
225
|
+
shareUpdatesIndex: number;
|
|
226
|
+
shares: string;
|
|
227
|
+
/** Unix seconds. */
|
|
228
|
+
timestamp: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
172
231
|
export interface LendingPortfolioQueryResult {
|
|
232
|
+
/** The block the subgraph answered at. */
|
|
233
|
+
_meta?: { block: { number: number } };
|
|
173
234
|
user: {
|
|
174
235
|
lendingPoolUserDetails: {
|
|
175
236
|
id: string;
|
|
237
|
+
totalAcceptedDeposits: string;
|
|
238
|
+
totalAcceptedWithdrawnAmount: string;
|
|
176
239
|
lendingPool: {
|
|
177
240
|
id: string;
|
|
178
241
|
name: string;
|
|
@@ -188,26 +251,32 @@ export interface LendingPortfolioQueryResult {
|
|
|
188
251
|
}[];
|
|
189
252
|
};
|
|
190
253
|
lendingPoolTrancheUserDetails: {
|
|
254
|
+
id: string;
|
|
191
255
|
shares: string;
|
|
192
256
|
userLendingPoolTrancheFixedTermDepositLocks: UserLendingPoolTrancheFixedTermDepositLock[];
|
|
257
|
+
/** The newest snapshot tagged before `$recentEpoch`. */
|
|
193
258
|
lendingPoolTrancheUserEpochSharesUpdates:
|
|
194
|
-
|
|
|
195
|
-
shares: string;
|
|
196
|
-
}[]
|
|
259
|
+
| PortfolioShareSnapshot[]
|
|
197
260
|
| undefined;
|
|
261
|
+
/** Every snapshot tagged `$recentEpoch` or later. */
|
|
262
|
+
recentUserShareUpdates: PortfolioShareSnapshot[] | undefined;
|
|
198
263
|
totalAcceptedDeposits: string;
|
|
199
264
|
totalAcceptedWithdrawnAmount: string;
|
|
200
265
|
tranche: {
|
|
201
266
|
id: string;
|
|
202
267
|
shares: string;
|
|
203
268
|
balance: string;
|
|
269
|
+
/** The newest snapshot tagged before `$recentEpoch`. */
|
|
204
270
|
lendingPoolTrancheShareUpdates:
|
|
205
|
-
|
|
|
206
|
-
|
|
207
|
-
|
|
271
|
+
| PortfolioShareSnapshot[]
|
|
272
|
+
| undefined;
|
|
273
|
+
/** Every snapshot tagged `$recentEpoch` or later. */
|
|
274
|
+
recentTrancheShareUpdates:
|
|
275
|
+
| PortfolioShareSnapshot[]
|
|
208
276
|
| undefined;
|
|
209
277
|
lendingPoolTrancheEpochInterest:
|
|
210
278
|
| {
|
|
279
|
+
epochId: string;
|
|
211
280
|
epochInterestAmount: string;
|
|
212
281
|
}[]
|
|
213
282
|
| undefined;
|
|
@@ -215,6 +284,22 @@ export interface LendingPortfolioQueryResult {
|
|
|
215
284
|
}[];
|
|
216
285
|
}[];
|
|
217
286
|
} | null;
|
|
287
|
+
/** The clearings of `$recentEpoch` up to the last settled epoch. */
|
|
288
|
+
lendingPoolClearings: {
|
|
289
|
+
id: string;
|
|
290
|
+
epochId: string;
|
|
291
|
+
startTimestamp: string;
|
|
292
|
+
lendingPool: { id: string };
|
|
293
|
+
}[];
|
|
294
|
+
/** Every share exit (any lender) in the listed tranches, those epochs. */
|
|
295
|
+
recentWithdrawalsAccepted: {
|
|
296
|
+
id: string;
|
|
297
|
+
type: 'WithdrawalAccepted' | 'ImmediateWithdrawalExecuted';
|
|
298
|
+
epochId: string;
|
|
299
|
+
createdOn: string;
|
|
300
|
+
sharesAmount: string | null;
|
|
301
|
+
tranche: { id: string };
|
|
302
|
+
}[];
|
|
218
303
|
userRequests: {
|
|
219
304
|
createdOn: string;
|
|
220
305
|
amountAccepted: string;
|