@sovryn-zero/lib-base 1.0.0-early.access.2 → 1.0.0-early.access.4

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 (35) hide show
  1. package/dist/src/LoC.d.ts +367 -0
  2. package/dist/src/LoC.d.ts.map +1 -0
  3. package/dist/src/LoC.js +423 -0
  4. package/dist/src/LoC.js.map +1 -0
  5. package/dist/src/ObservableZero.d.ts +15 -0
  6. package/dist/src/ObservableZero.d.ts.map +1 -0
  7. package/dist/src/ObservableZero.js +3 -0
  8. package/dist/src/ObservableZero.js.map +1 -0
  9. package/dist/src/PopulatableZero.d.ts +125 -0
  10. package/dist/src/PopulatableZero.d.ts.map +1 -0
  11. package/dist/src/PopulatableZero.js +3 -0
  12. package/dist/src/PopulatableZero.js.map +1 -0
  13. package/dist/src/ReadableZero.d.ts +156 -0
  14. package/dist/src/ReadableZero.d.ts.map +1 -0
  15. package/dist/src/ReadableZero.js +3 -0
  16. package/dist/src/ReadableZero.js.map +1 -0
  17. package/dist/src/SendableZero.d.ts +156 -0
  18. package/dist/src/SendableZero.d.ts.map +1 -0
  19. package/dist/src/SendableZero.js +20 -0
  20. package/dist/src/SendableZero.js.map +1 -0
  21. package/dist/src/TransactableZero.d.ts +414 -0
  22. package/dist/src/TransactableZero.d.ts.map +1 -0
  23. package/dist/src/TransactableZero.js +18 -0
  24. package/dist/src/TransactableZero.js.map +1 -0
  25. package/dist/src/ZeroStore.d.ts +209 -0
  26. package/dist/src/ZeroStore.d.ts.map +1 -0
  27. package/dist/src/ZeroStore.js +209 -0
  28. package/dist/src/ZeroStore.js.map +1 -0
  29. package/dist/src/_CachedReadableZero.d.ts +55 -0
  30. package/dist/src/_CachedReadableZero.d.ts.map +1 -0
  31. package/dist/src/_CachedReadableZero.js +93 -0
  32. package/dist/src/_CachedReadableZero.js.map +1 -0
  33. package/dist/src/constants.js +2 -2
  34. package/package.json +2 -2
  35. package/src/constants.ts +2 -2
@@ -0,0 +1,414 @@
1
+ import { Decimal, Decimalish } from "./Decimal";
2
+ import { Trove, TroveAdjustmentParams, TroveClosureParams, TroveCreationParams } from "./Trove";
3
+ import { StabilityDepositChange } from "./StabilityDeposit";
4
+ import { FailedReceipt } from "./SendableLiquity";
5
+ /**
6
+ * Thrown by {@link TransactableLiquity} functions in case of transaction failure.
7
+ *
8
+ * @public
9
+ */
10
+ export declare class TransactionFailedError<T extends FailedReceipt = FailedReceipt> extends Error {
11
+ readonly failedReceipt: T;
12
+ /** @internal */
13
+ constructor(name: string, message: string, failedReceipt: T);
14
+ }
15
+ /**
16
+ * Details of an {@link TransactableLiquity.openTrove | openTrove()} transaction.
17
+ *
18
+ * @public
19
+ */
20
+ export interface TroveCreationDetails {
21
+ /** How much was deposited and borrowed. */
22
+ params: TroveCreationParams<Decimal>;
23
+ /** The Trove that was created by the transaction. */
24
+ newTrove: Trove;
25
+ /** Amount of ZUSD added to the Trove's debt as borrowing fee. */
26
+ fee: Decimal;
27
+ }
28
+ /**
29
+ * Details of an {@link TransactableLiquity.adjustTrove | adjustTrove()} transaction.
30
+ *
31
+ * @public
32
+ */
33
+ export interface TroveAdjustmentDetails {
34
+ /** Parameters of the adjustment. */
35
+ params: TroveAdjustmentParams<Decimal>;
36
+ /** New state of the adjusted Trove directly after the transaction. */
37
+ newTrove: Trove;
38
+ /** Amount of ZUSD added to the Trove's debt as borrowing fee. */
39
+ fee: Decimal;
40
+ }
41
+ /**
42
+ * Details of a {@link TransactableLiquity.closeTrove | closeTrove()} transaction.
43
+ *
44
+ * @public
45
+ */
46
+ export interface TroveClosureDetails {
47
+ /** How much was withdrawn and repaid. */
48
+ params: TroveClosureParams<Decimal>;
49
+ }
50
+ /**
51
+ * Details of a {@link TransactableLiquity.liquidate | liquidate()} or
52
+ * {@link TransactableLiquity.liquidateUpTo | liquidateUpTo()} transaction.
53
+ *
54
+ * @public
55
+ */
56
+ export interface LiquidationDetails {
57
+ /** Addresses whose Troves were liquidated by the transaction. */
58
+ liquidatedAddresses: string[];
59
+ /** Total collateral liquidated and debt cleared by the transaction. */
60
+ totalLiquidated: Trove;
61
+ /** Amount of ZUSD paid to the liquidator as gas compensation. */
62
+ zusdGasCompensation: Decimal;
63
+ /** Amount of native currency (e.g. Ether) paid to the liquidator as gas compensation. */
64
+ collateralGasCompensation: Decimal;
65
+ }
66
+ /**
67
+ * Details of a {@link TransactableLiquity.redeemZUSD | redeemZUSD()} transaction.
68
+ *
69
+ * @public
70
+ */
71
+ export interface RedemptionDetails {
72
+ /** Amount of ZUSD the redeemer tried to redeem. */
73
+ attemptedZUSDAmount: Decimal;
74
+ /**
75
+ * Amount of ZUSD that was actually redeemed by the transaction.
76
+ *
77
+ * @remarks
78
+ * This can end up being lower than `attemptedZUSDAmount` due to interference from another
79
+ * transaction that modifies the list of Troves.
80
+ *
81
+ * @public
82
+ */
83
+ actualZUSDAmount: Decimal;
84
+ /** Amount of collateral (e.g. Ether) taken from Troves by the transaction. */
85
+ collateralTaken: Decimal;
86
+ /** Amount of native currency (e.g. Ether) deducted as fee from collateral taken. */
87
+ fee: Decimal;
88
+ }
89
+ /**
90
+ * Details of a
91
+ * {@link TransactableLiquity.withdrawGainsFromStabilityPool | withdrawGainsFromStabilityPool()}
92
+ * transaction.
93
+ *
94
+ * @public
95
+ */
96
+ export interface StabilityPoolGainsWithdrawalDetails {
97
+ /** Amount of ZUSD burned from the deposit by liquidations since the last modification. */
98
+ zusdLoss: Decimal;
99
+ /** Amount of ZUSD in the deposit directly after this transaction. */
100
+ newZUSDDeposit: Decimal;
101
+ /** Amount of native currency (e.g. Ether) paid out to the depositor in this transaction. */
102
+ collateralGain: Decimal;
103
+ /** Amount of ZERO rewarded to the depositor in this transaction. */
104
+ zeroReward: Decimal;
105
+ }
106
+ /**
107
+ * Details of a
108
+ * {@link TransactableLiquity.depositZUSDInStabilityPool | depositZUSDInStabilityPool()} or
109
+ * {@link TransactableLiquity.withdrawZUSDFromStabilityPool | withdrawZUSDFromStabilityPool()}
110
+ * transaction.
111
+ *
112
+ * @public
113
+ */
114
+ export interface StabilityDepositChangeDetails extends StabilityPoolGainsWithdrawalDetails {
115
+ /** Change that was made to the deposit by this transaction. */
116
+ change: StabilityDepositChange<Decimal>;
117
+ }
118
+ /**
119
+ * Details of a
120
+ * {@link TransactableLiquity.transferCollateralGainToTrove | transferCollateralGainToTrove()}
121
+ * transaction.
122
+ *
123
+ * @public
124
+ */
125
+ export interface CollateralGainTransferDetails extends StabilityPoolGainsWithdrawalDetails {
126
+ /** New state of the depositor's Trove directly after the transaction. */
127
+ newTrove: Trove;
128
+ }
129
+ /**
130
+ * Send Zero transactions and wait for them to succeed.
131
+ *
132
+ * @remarks
133
+ * The functions return the details of the transaction (if any), or throw an implementation-specific
134
+ * subclass of {@link TransactionFailedError} in case of transaction failure.
135
+ *
136
+ * Implemented by {@link @sovryn-zero/lib-ethers#EthersLiquity}.
137
+ *
138
+ * @public
139
+ */
140
+ export interface TransactableLiquity {
141
+ /**
142
+ * Open a new Trove by depositing collateral and borrowing ZUSD.
143
+ *
144
+ * @param params - How much to deposit and borrow.
145
+ * @param maxBorrowingRate - Maximum acceptable
146
+ * {@link @sovryn-zero/lib-base#Fees.borrowingRate | borrowing rate}.
147
+ *
148
+ * @throws
149
+ * Throws {@link TransactionFailedError} in case of transaction failure.
150
+ *
151
+ * @remarks
152
+ * If `maxBorrowingRate` is omitted, the current borrowing rate plus 0.5% is used as maximum
153
+ * acceptable rate.
154
+ */
155
+ openTrove(params: TroveCreationParams<Decimalish>, maxBorrowingRate?: Decimalish): Promise<TroveCreationDetails>;
156
+ /**
157
+ * Close existing Trove by repaying all debt and withdrawing all collateral.
158
+ *
159
+ * @throws
160
+ * Throws {@link TransactionFailedError} in case of transaction failure.
161
+ */
162
+ closeTrove(): Promise<TroveClosureDetails>;
163
+ /**
164
+ * Adjust existing Trove by changing its collateral, debt, or both.
165
+ *
166
+ * @param params - Parameters of the adjustment.
167
+ * @param maxBorrowingRate - Maximum acceptable
168
+ * {@link @sovryn-zero/lib-base#Fees.borrowingRate | borrowing rate} if
169
+ * `params` includes `borrowZUSD`.
170
+ *
171
+ * @throws
172
+ * Throws {@link TransactionFailedError} in case of transaction failure.
173
+ *
174
+ * @remarks
175
+ * The transaction will fail if the Trove's debt would fall below
176
+ * {@link @sovryn-zero/lib-base#ZUSD_MINIMUM_DEBT}.
177
+ *
178
+ * If `maxBorrowingRate` is omitted, the current borrowing rate plus 0.5% is used as maximum
179
+ * acceptable rate.
180
+ */
181
+ adjustTrove(params: TroveAdjustmentParams<Decimalish>, maxBorrowingRate?: Decimalish): Promise<TroveAdjustmentDetails>;
182
+ /**
183
+ * Adjust existing Trove by depositing more collateral.
184
+ *
185
+ * @param amount - The amount of collateral to add to the Trove's existing collateral.
186
+ *
187
+ * @throws
188
+ * Throws {@link TransactionFailedError} in case of transaction failure.
189
+ *
190
+ * @remarks
191
+ * Equivalent to:
192
+ *
193
+ * ```typescript
194
+ * adjustTrove({ depositCollateral: amount })
195
+ * ```
196
+ */
197
+ depositCollateral(amount: Decimalish): Promise<TroveAdjustmentDetails>;
198
+ /**
199
+ * Adjust existing Trove by withdrawing some of its collateral.
200
+ *
201
+ * @param amount - The amount of collateral to withdraw from the Trove.
202
+ *
203
+ * @throws
204
+ * Throws {@link TransactionFailedError} in case of transaction failure.
205
+ *
206
+ * @remarks
207
+ * Equivalent to:
208
+ *
209
+ * ```typescript
210
+ * adjustTrove({ withdrawCollateral: amount })
211
+ * ```
212
+ */
213
+ withdrawCollateral(amount: Decimalish): Promise<TroveAdjustmentDetails>;
214
+ /**
215
+ * Adjust existing Trove by borrowing more ZUSD.
216
+ *
217
+ * @param amount - The amount of ZUSD to borrow.
218
+ * @param maxBorrowingRate - Maximum acceptable
219
+ * {@link @sovryn-zero/lib-base#Fees.borrowingRate | borrowing rate}.
220
+ *
221
+ * @throws
222
+ * Throws {@link TransactionFailedError} in case of transaction failure.
223
+ *
224
+ * @remarks
225
+ * Equivalent to:
226
+ *
227
+ * ```typescript
228
+ * adjustTrove({ borrowZUSD: amount }, maxBorrowingRate)
229
+ * ```
230
+ */
231
+ borrowZUSD(amount: Decimalish, maxBorrowingRate?: Decimalish): Promise<TroveAdjustmentDetails>;
232
+ /**
233
+ * Adjust existing Trove by repaying some of its debt.
234
+ *
235
+ * @param amount - The amount of ZUSD to repay.
236
+ *
237
+ * @throws
238
+ * Throws {@link TransactionFailedError} in case of transaction failure.
239
+ *
240
+ * @remarks
241
+ * Equivalent to:
242
+ *
243
+ * ```typescript
244
+ * adjustTrove({ repayZUSD: amount })
245
+ * ```
246
+ */
247
+ repayZUSD(amount: Decimalish): Promise<TroveAdjustmentDetails>;
248
+ /** @internal */
249
+ setPrice(price: Decimalish): Promise<void>;
250
+ /**
251
+ * Liquidate one or more undercollateralized Troves.
252
+ *
253
+ * @param address - Address or array of addresses whose Troves to liquidate.
254
+ *
255
+ * @throws
256
+ * Throws {@link TransactionFailedError} in case of transaction failure.
257
+ */
258
+ liquidate(address: string | string[]): Promise<LiquidationDetails>;
259
+ /**
260
+ * Liquidate the least collateralized Troves up to a maximum number.
261
+ *
262
+ * @param maximumNumberOfTrovesToLiquidate - Stop after liquidating this many Troves.
263
+ *
264
+ * @throws
265
+ * Throws {@link TransactionFailedError} in case of transaction failure.
266
+ */
267
+ liquidateUpTo(maximumNumberOfTrovesToLiquidate: number): Promise<LiquidationDetails>;
268
+ /**
269
+ * Make a new Stability Deposit, or top up existing one.
270
+ *
271
+ * @param amount - Amount of ZUSD to add to new or existing deposit.
272
+ * @param frontendTag - Address that should receive a share of this deposit's ZERO rewards.
273
+ *
274
+ * @throws
275
+ * Throws {@link TransactionFailedError} in case of transaction failure.
276
+ *
277
+ * @remarks
278
+ * The `frontendTag` parameter is only effective when making a new deposit.
279
+ *
280
+ * As a side-effect, the transaction will also pay out an existing Stability Deposit's
281
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} and
282
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward}.
283
+ */
284
+ depositZUSDInStabilityPool(amount: Decimalish, frontendTag?: string): Promise<StabilityDepositChangeDetails>;
285
+ /**
286
+ * Withdraw ZUSD from Stability Deposit.
287
+ *
288
+ * @param amount - Amount of ZUSD to withdraw.
289
+ *
290
+ * @throws
291
+ * Throws {@link TransactionFailedError} in case of transaction failure.
292
+ *
293
+ * @remarks
294
+ * As a side-effect, the transaction will also pay out the Stability Deposit's
295
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} and
296
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward}.
297
+ */
298
+ withdrawZUSDFromStabilityPool(amount: Decimalish): Promise<StabilityDepositChangeDetails>;
299
+ /**
300
+ * Withdraw {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} and
301
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward} from Stability Deposit.
302
+ *
303
+ * @throws
304
+ * Throws {@link TransactionFailedError} in case of transaction failure.
305
+ */
306
+ withdrawGainsFromStabilityPool(): Promise<StabilityPoolGainsWithdrawalDetails>;
307
+ /**
308
+ * Transfer {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} from
309
+ * Stability Deposit to Trove.
310
+ *
311
+ * @throws
312
+ * Throws {@link TransactionFailedError} in case of transaction failure.
313
+ *
314
+ * @remarks
315
+ * The collateral gain is transfered to the Trove as additional collateral.
316
+ *
317
+ * As a side-effect, the transaction will also pay out the Stability Deposit's
318
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward}.
319
+ */
320
+ transferCollateralGainToTrove(): Promise<CollateralGainTransferDetails>;
321
+ /**
322
+ * Send ZUSD tokens to an address.
323
+ *
324
+ * @param toAddress - Address of receipient.
325
+ * @param amount - Amount of ZUSD to send.
326
+ *
327
+ * @throws
328
+ * Throws {@link TransactionFailedError} in case of transaction failure.
329
+ */
330
+ sendZUSD(toAddress: string, amount: Decimalish): Promise<void>;
331
+ /**
332
+ * Send ZERO tokens to an address.
333
+ *
334
+ * @param toAddress - Address of receipient.
335
+ * @param amount - Amount of ZERO to send.
336
+ *
337
+ * @throws
338
+ * Throws {@link TransactionFailedError} in case of transaction failure.
339
+ */
340
+ sendZERO(toAddress: string, amount: Decimalish): Promise<void>;
341
+ /**
342
+ * Redeem ZUSD to native currency (e.g. Ether) at face value.
343
+ *
344
+ * @param amount - Amount of ZUSD to be redeemed.
345
+ * @param maxRedemptionRate - Maximum acceptable
346
+ * {@link @sovryn-zero/lib-base#Fees.redemptionRate | redemption rate}.
347
+ *
348
+ * @throws
349
+ * Throws {@link TransactionFailedError} in case of transaction failure.
350
+ *
351
+ * @remarks
352
+ * If `maxRedemptionRate` is omitted, the current redemption rate (based on `amount`) plus 0.1%
353
+ * is used as maximum acceptable rate.
354
+ */
355
+ redeemZUSD(amount: Decimalish, maxRedemptionRate?: Decimalish): Promise<RedemptionDetails>;
356
+ /**
357
+ * Claim leftover collateral after a liquidation or redemption.
358
+ *
359
+ * @remarks
360
+ * Use {@link @sovryn-zero/lib-base#ReadableLiquity.getCollateralSurplusBalance | getCollateralSurplusBalance()}
361
+ * to check the amount of collateral available for withdrawal.
362
+ *
363
+ * @throws
364
+ * Throws {@link TransactionFailedError} in case of transaction failure.
365
+ */
366
+ claimCollateralSurplus(): Promise<void>;
367
+ /**
368
+ * Stake ZERO to start earning fee revenue or increase existing stake.
369
+ *
370
+ * @param amount - Amount of ZERO to add to new or existing stake.
371
+ *
372
+ * @throws
373
+ * Throws {@link TransactionFailedError} in case of transaction failure.
374
+ *
375
+ * @remarks
376
+ * As a side-effect, the transaction will also pay out an existing ZERO stake's
377
+ * {@link @sovryn-zero/lib-base#ZEROStake.collateralGain | collateral gain} and
378
+ * {@link @sovryn-zero/lib-base#ZEROStake.zusdGain | ZUSD gain}.
379
+ */
380
+ stakeZERO(amount: Decimalish): Promise<void>;
381
+ /**
382
+ * Withdraw ZERO from staking.
383
+ *
384
+ * @param amount - Amount of ZERO to withdraw.
385
+ *
386
+ * @throws
387
+ * Throws {@link TransactionFailedError} in case of transaction failure.
388
+ *
389
+ * @remarks
390
+ * As a side-effect, the transaction will also pay out the ZERO stake's
391
+ * {@link @sovryn-zero/lib-base#ZEROStake.collateralGain | collateral gain} and
392
+ * {@link @sovryn-zero/lib-base#ZEROStake.zusdGain | ZUSD gain}.
393
+ */
394
+ unstakeZERO(amount: Decimalish): Promise<void>;
395
+ /**
396
+ * Withdraw {@link @sovryn-zero/lib-base#ZEROStake.collateralGain | collateral gain} and
397
+ * {@link @sovryn-zero/lib-base#ZEROStake.zusdGain | ZUSD gain} from ZERO stake.
398
+ *
399
+ * @throws
400
+ * Throws {@link TransactionFailedError} in case of transaction failure.
401
+ */
402
+ withdrawGainsFromStaking(): Promise<void>;
403
+ /**
404
+ * Register current wallet address as a Zero frontend.
405
+ *
406
+ * @param kickbackRate - The portion of ZERO rewards to pass onto users of the frontend
407
+ * (between 0 and 1).
408
+ *
409
+ * @throws
410
+ * Throws {@link TransactionFailedError} in case of transaction failure.
411
+ */
412
+ registerFrontend(kickbackRate: Decimalish): Promise<void>;
413
+ }
414
+ //# sourceMappingURL=TransactableLiquity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactableLiquity.d.ts","sourceRoot":"","sources":["../../src/TransactableLiquity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,CAAE,SAAQ,KAAK;IACxF,QAAQ,CAAC,aAAa,EAAE,C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,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;;;OAMG;IACH,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C;;;;;;;;OAQG;IACH,gBAAgB,CAAC,YAAY,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionFailedError = void 0;
4
+ /**
5
+ * Thrown by {@link TransactableLiquity} functions in case of transaction failure.
6
+ *
7
+ * @public
8
+ */
9
+ class TransactionFailedError extends Error {
10
+ /** @internal */
11
+ constructor(name, message, failedReceipt) {
12
+ super(message);
13
+ this.name = name;
14
+ this.failedReceipt = failedReceipt;
15
+ }
16
+ }
17
+ exports.TransactionFailedError = TransactionFailedError;
18
+ //# sourceMappingURL=TransactableLiquity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactableLiquity.js","sourceRoot":"","sources":["../../src/TransactableLiquity.ts"],"names":[],"mappings":";;;AAKA;;;;GAIG;AACH,MAAa,sBAAgE,SAAQ,KAAK;IAGxF,gBAAgB;IAChB,YAAY,IAAY,EAAE,OAAe,EAAE,aAAgB;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AATD,wDASC"}
@@ -0,0 +1,209 @@
1
+ import { Decimal } from "./Decimal";
2
+ import { StabilityDeposit } from "./StabilityDeposit";
3
+ import { Trove, TroveWithPendingRedistribution, UserTrove } from "./Trove";
4
+ import { Fees } from "./Fees";
5
+ import { ZEROStake } from "./ZEROStake";
6
+ import { FrontendStatus } from "./ReadableLiquity";
7
+ /**
8
+ * State variables read from the blockchain.
9
+ *
10
+ * @public
11
+ */
12
+ export interface LiquityStoreBaseState {
13
+ /** Status of currently used frontend. */
14
+ frontend: FrontendStatus;
15
+ /** Status of user's own frontend. */
16
+ ownFrontend: FrontendStatus;
17
+ /** Number of Troves that are currently open. */
18
+ numberOfTroves: number;
19
+ /** User's native currency balance (e.g. Ether). */
20
+ accountBalance: Decimal;
21
+ /** User's ZUSD token balance. */
22
+ zusdBalance: Decimal;
23
+ /** User's NUE token balance. */
24
+ nueBalance: Decimal;
25
+ /** User's ZERO token balance. */
26
+ zeroBalance: Decimal;
27
+ /**
28
+ * Amount of leftover collateral available for withdrawal to the user.
29
+ *
30
+ * @remarks
31
+ * See {@link ReadableLiquity.getCollateralSurplusBalance | getCollateralSurplusBalance()} for
32
+ * more information.
33
+ */
34
+ collateralSurplusBalance: Decimal;
35
+ /** Current price of the native currency (e.g. Ether) in USD. */
36
+ price: Decimal;
37
+ /** Total amount of ZUSD currently deposited in the Stability Pool. */
38
+ zusdInStabilityPool: Decimal;
39
+ /** Total collateral and debt in the Zero system. */
40
+ total: Trove;
41
+ /**
42
+ * Total collateral and debt per stake that has been liquidated through redistribution.
43
+ *
44
+ * @remarks
45
+ * Needed when dealing with instances of {@link TroveWithPendingRedistribution}.
46
+ */
47
+ totalRedistributed: Trove;
48
+ /**
49
+ * User's Trove in its state after the last direct modification.
50
+ *
51
+ * @remarks
52
+ * The current state of the user's Trove can be found as
53
+ * {@link LiquityStoreDerivedState.trove | trove}.
54
+ */
55
+ troveBeforeRedistribution: TroveWithPendingRedistribution;
56
+ /** User's stability deposit. */
57
+ stabilityDeposit: StabilityDeposit;
58
+ /** Remaining ZERO that will be collectively rewarded to stability depositors. */
59
+ remainingStabilityPoolZEROReward: Decimal;
60
+ /** @internal */
61
+ _feesInNormalMode: Fees;
62
+ /** User's ZERO stake. */
63
+ zeroStake: ZEROStake;
64
+ /** Total amount of ZERO currently staked. */
65
+ totalStakedZERO: Decimal;
66
+ /** @internal */
67
+ _riskiestTroveBeforeRedistribution: TroveWithPendingRedistribution;
68
+ }
69
+ /**
70
+ * State variables derived from {@link LiquityStoreBaseState}.
71
+ *
72
+ * @public
73
+ */
74
+ export interface LiquityStoreDerivedState {
75
+ /** Current state of user's Trove */
76
+ trove: UserTrove;
77
+ /** Calculator for current fees. */
78
+ fees: Fees;
79
+ /**
80
+ * Current borrowing rate.
81
+ *
82
+ * @remarks
83
+ * A value between 0 and 1.
84
+ *
85
+ * @example
86
+ * For example a value of 0.01 amounts to a borrowing fee of 1% of the borrowed amount.
87
+ */
88
+ borrowingRate: Decimal;
89
+ /**
90
+ * Current redemption rate.
91
+ *
92
+ * @remarks
93
+ * Note that the actual rate paid by a redemption transaction will depend on the amount of ZUSD
94
+ * being redeemed.
95
+ *
96
+ * Use {@link Fees.redemptionRate} to calculate a precise redemption rate.
97
+ */
98
+ redemptionRate: Decimal;
99
+ /**
100
+ * Whether there are any Troves with collateral ratio below the
101
+ * {@link MINIMUM_COLLATERAL_RATIO | minimum}.
102
+ */
103
+ haveUndercollateralizedTroves: boolean;
104
+ }
105
+ /**
106
+ * Type of {@link LiquityStore}'s {@link LiquityStore.state | state}.
107
+ *
108
+ * @remarks
109
+ * It combines all properties of {@link LiquityStoreBaseState} and {@link LiquityStoreDerivedState}
110
+ * with optional extra state added by the particular `LiquityStore` implementation.
111
+ *
112
+ * The type parameter `T` may be used to type the extra state.
113
+ *
114
+ * @public
115
+ */
116
+ export declare type LiquityStoreState<T = unknown> = LiquityStoreBaseState & LiquityStoreDerivedState & T;
117
+ /**
118
+ * Parameters passed to {@link LiquityStore} listeners.
119
+ *
120
+ * @remarks
121
+ * Use the {@link LiquityStore.subscribe | subscribe()} function to register a listener.
122
+
123
+ * @public
124
+ */
125
+ export interface LiquityStoreListenerParams<T = unknown> {
126
+ /** The entire previous state. */
127
+ newState: LiquityStoreState<T>;
128
+ /** The entire new state. */
129
+ oldState: LiquityStoreState<T>;
130
+ /** Only the state variables that have changed. */
131
+ stateChange: Partial<LiquityStoreState<T>>;
132
+ }
133
+ /**
134
+ * Abstract base class of Zero data store implementations.
135
+ *
136
+ * @remarks
137
+ * The type parameter `T` may be used to type extra state added to {@link LiquityStoreState} by the
138
+ * subclass.
139
+ *
140
+ * Implemented by {@link @sovryn-zero/lib-ethers#BlockPolledLiquityStore}.
141
+ *
142
+ * @public
143
+ */
144
+ export declare abstract class LiquityStore<T = unknown> {
145
+ /** Turn console logging on/off. */
146
+ logging: boolean;
147
+ /**
148
+ * Called after the state is fetched for the first time.
149
+ *
150
+ * @remarks
151
+ * See {@link LiquityStore.start | start()}.
152
+ */
153
+ onLoaded?: () => void;
154
+ /** @internal */
155
+ protected _loaded: boolean;
156
+ private _baseState?;
157
+ private _derivedState?;
158
+ private _extraState?;
159
+ private _updateTimeoutId;
160
+ private _listeners;
161
+ /**
162
+ * The current store state.
163
+ *
164
+ * @remarks
165
+ * Should not be accessed before the store is loaded. Assign a function to
166
+ * {@link LiquityStore.onLoaded | onLoaded} to get a callback when this happens.
167
+ *
168
+ * See {@link LiquityStoreState} for the list of properties returned.
169
+ */
170
+ get state(): LiquityStoreState<T>;
171
+ /** @internal */
172
+ protected abstract _doStart(): () => void;
173
+ /**
174
+ * Start monitoring the blockchain for Zero state changes.
175
+ *
176
+ * @remarks
177
+ * The {@link LiquityStore.onLoaded | onLoaded} callback will be called after the state is fetched
178
+ * for the first time.
179
+ *
180
+ * Use the {@link LiquityStore.subscribe | subscribe()} function to register listeners.
181
+ *
182
+ * @returns Function to stop the monitoring.
183
+ */
184
+ start(): () => void;
185
+ private _cancelUpdateIfScheduled;
186
+ private _scheduleUpdate;
187
+ private _logUpdate;
188
+ private _updateIfChanged;
189
+ private _silentlyUpdateIfChanged;
190
+ private _updateFees;
191
+ private _reduce;
192
+ private _derive;
193
+ private _reduceDerived;
194
+ /** @internal */
195
+ protected abstract _reduceExtra(extraState: T, extraStateUpdate: Partial<T>): T;
196
+ private _notify;
197
+ /**
198
+ * Register a state change listener.
199
+ *
200
+ * @param listener - Function that will be called whenever state changes.
201
+ * @returns Function to unregister this listener.
202
+ */
203
+ subscribe(listener: (params: LiquityStoreListenerParams<T>) => void): () => void;
204
+ /** @internal */
205
+ protected _load(baseState: LiquityStoreBaseState, extraState?: T): void;
206
+ /** @internal */
207
+ protected _update(baseStateUpdate?: Partial<LiquityStoreBaseState>, extraStateUpdate?: Partial<T>): void;
208
+ }
209
+ //# sourceMappingURL=LiquityStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiquityStore.d.ts","sourceRoot":"","sources":["../../src/LiquityStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,8BAA8B,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,QAAQ,EAAE,cAAc,CAAC;IAEzB,qCAAqC;IACrC,WAAW,EAAE,cAAc,CAAC;IAE5B,gDAAgD;IAChD,cAAc,EAAE,MAAM,CAAC;IAEvB,mDAAmD;IACnD,cAAc,EAAE,OAAO,CAAC;IAExB,iCAAiC;IACjC,WAAW,EAAE,OAAO,CAAC;IAErB,gCAAgC;IAChC,UAAU,EAAE,OAAO,CAAC;IAEpB,iCAAiC;IACjC,WAAW,EAAE,OAAO,CAAC;IAErB;;;;;;OAMG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAElC,gEAAgE;IAChE,KAAK,EAAE,OAAO,CAAC;IAEf,sEAAsE;IACtE,mBAAmB,EAAE,OAAO,CAAC;IAE7B,oDAAoD;IACpD,KAAK,EAAE,KAAK,CAAC;IAEb;;;;;OAKG;IACH,kBAAkB,EAAE,KAAK,CA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