@sovryn-zero/lib-base 0.1.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.
Files changed (84) hide show
  1. package/.eslintrc.json +17 -0
  2. package/.mocharc.yml +1 -0
  3. package/LICENSE +905 -0
  4. package/README.md +23 -0
  5. package/api-extractor.json +4 -0
  6. package/dist/index.d.ts +14 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +26 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/src/Decimal.d.ts +89 -0
  11. package/dist/src/Decimal.d.ts.map +1 -0
  12. package/dist/src/Decimal.js +361 -0
  13. package/dist/src/Decimal.js.map +1 -0
  14. package/dist/src/Fees.d.ts +82 -0
  15. package/dist/src/Fees.d.ts.map +1 -0
  16. package/dist/src/Fees.js +123 -0
  17. package/dist/src/Fees.js.map +1 -0
  18. package/dist/src/LiquityStore.d.ts +209 -0
  19. package/dist/src/LiquityStore.d.ts.map +1 -0
  20. package/dist/src/LiquityStore.js +209 -0
  21. package/dist/src/LiquityStore.js.map +1 -0
  22. package/dist/src/ObservableLiquity.d.ts +15 -0
  23. package/dist/src/ObservableLiquity.d.ts.map +1 -0
  24. package/dist/src/ObservableLiquity.js +3 -0
  25. package/dist/src/ObservableLiquity.js.map +1 -0
  26. package/dist/src/PopulatableLiquity.d.ts +125 -0
  27. package/dist/src/PopulatableLiquity.d.ts.map +1 -0
  28. package/dist/src/PopulatableLiquity.js +3 -0
  29. package/dist/src/PopulatableLiquity.js.map +1 -0
  30. package/dist/src/ReadableLiquity.d.ts +156 -0
  31. package/dist/src/ReadableLiquity.d.ts.map +1 -0
  32. package/dist/src/ReadableLiquity.js +3 -0
  33. package/dist/src/ReadableLiquity.js.map +1 -0
  34. package/dist/src/SendableLiquity.d.ts +156 -0
  35. package/dist/src/SendableLiquity.d.ts.map +1 -0
  36. package/dist/src/SendableLiquity.js +20 -0
  37. package/dist/src/SendableLiquity.js.map +1 -0
  38. package/dist/src/StabilityDeposit.d.ts +59 -0
  39. package/dist/src/StabilityDeposit.d.ts.map +1 -0
  40. package/dist/src/StabilityDeposit.js +80 -0
  41. package/dist/src/StabilityDeposit.js.map +1 -0
  42. package/dist/src/TransactableLiquity.d.ts +414 -0
  43. package/dist/src/TransactableLiquity.d.ts.map +1 -0
  44. package/dist/src/TransactableLiquity.js +18 -0
  45. package/dist/src/TransactableLiquity.js.map +1 -0
  46. package/dist/src/Trove.d.ts +367 -0
  47. package/dist/src/Trove.d.ts.map +1 -0
  48. package/dist/src/Trove.js +423 -0
  49. package/dist/src/Trove.js.map +1 -0
  50. package/dist/src/ZEROStake.d.ts +52 -0
  51. package/dist/src/ZEROStake.d.ts.map +1 -0
  52. package/dist/src/ZEROStake.js +74 -0
  53. package/dist/src/ZEROStake.js.map +1 -0
  54. package/dist/src/_CachedReadableLiquity.d.ts +55 -0
  55. package/dist/src/_CachedReadableLiquity.d.ts.map +1 -0
  56. package/dist/src/_CachedReadableLiquity.js +93 -0
  57. package/dist/src/_CachedReadableLiquity.js.map +1 -0
  58. package/dist/src/constants.d.ts +61 -0
  59. package/dist/src/constants.d.ts.map +1 -0
  60. package/dist/src/constants.js +64 -0
  61. package/dist/src/constants.js.map +1 -0
  62. package/dist/tsdoc-metadata.json +11 -0
  63. package/etc/lib-base.api.md +788 -0
  64. package/index.ts +13 -0
  65. package/package.json +52 -0
  66. package/src/Decimal.ts +456 -0
  67. package/src/Fees.ts +160 -0
  68. package/src/LiquityStore.ts +563 -0
  69. package/src/ObservableLiquity.ts +32 -0
  70. package/src/PopulatableLiquity.ts +280 -0
  71. package/src/ReadableLiquity.ts +175 -0
  72. package/src/SendableLiquity.ts +251 -0
  73. package/src/StabilityDeposit.ts +126 -0
  74. package/src/TransactableLiquity.ts +471 -0
  75. package/src/Trove.ts +824 -0
  76. package/src/ZEROStake.ts +99 -0
  77. package/src/_CachedReadableLiquity.ts +186 -0
  78. package/src/constants.ts +68 -0
  79. package/test/Decimal.test.ts +212 -0
  80. package/test/StabilityDeposit.test.ts +30 -0
  81. package/test/Trove.test.ts +143 -0
  82. package/test/ZEROStake.test.ts +24 -0
  83. package/tsconfig.dist.json +8 -0
  84. package/tsconfig.json +5 -0
@@ -0,0 +1,126 @@
1
+ import { Decimal, Decimalish } from "./Decimal";
2
+
3
+ /**
4
+ * Represents the change between two Stability Deposit states.
5
+ *
6
+ * @public
7
+ */
8
+ export type StabilityDepositChange<T> =
9
+ | { depositZUSD: T; withdrawZUSD?: undefined }
10
+ | { depositZUSD?: undefined; withdrawZUSD: T; withdrawAllZUSD: boolean };
11
+
12
+ /**
13
+ * A Stability Deposit and its accrued gains.
14
+ *
15
+ * @public
16
+ */
17
+ export class StabilityDeposit {
18
+ /** Amount of ZUSD in the Stability Deposit at the time of the last direct modification. */
19
+ readonly initialZUSD: Decimal;
20
+
21
+ /** Amount of ZUSD left in the Stability Deposit. */
22
+ readonly currentZUSD: Decimal;
23
+
24
+ /** Amount of native currency (e.g. Ether) received in exchange for the used-up ZUSD. */
25
+ readonly collateralGain: Decimal;
26
+
27
+ /** Amount of ZERO rewarded since the last modification of the Stability Deposit. */
28
+ readonly zeroReward: Decimal;
29
+
30
+ /**
31
+ * Address of frontend through which this Stability Deposit was made.
32
+ *
33
+ * @remarks
34
+ * If the Stability Deposit was made through a frontend that doesn't tag deposits, this will be
35
+ * the zero-address.
36
+ */
37
+ readonly frontendTag: string;
38
+
39
+ /** @internal */
40
+ constructor(
41
+ initialZUSD: Decimal,
42
+ currentZUSD: Decimal,
43
+ collateralGain: Decimal,
44
+ zeroReward: Decimal,
45
+ frontendTag: string
46
+ ) {
47
+ this.initialZUSD = initialZUSD;
48
+ this.currentZUSD = currentZUSD;
49
+ this.collateralGain = collateralGain;
50
+ this.zeroReward = zeroReward;
51
+ this.frontendTag = frontendTag;
52
+
53
+ if (this.currentZUSD.gt(this.initialZUSD)) {
54
+ throw new Error("currentZUSD can't be greater than initialZUSD");
55
+ }
56
+ }
57
+
58
+ get isEmpty(): boolean {
59
+ return (
60
+ this.initialZUSD.isZero &&
61
+ this.currentZUSD.isZero &&
62
+ this.collateralGain.isZero &&
63
+ this.zeroReward.isZero
64
+ );
65
+ }
66
+
67
+ /** @internal */
68
+ toString(): string {
69
+ return (
70
+ `{ initialZUSD: ${this.initialZUSD}` +
71
+ `, currentZUSD: ${this.currentZUSD}` +
72
+ `, collateralGain: ${this.collateralGain}` +
73
+ `, zeroReward: ${this.zeroReward}` +
74
+ `, frontendTag: "${this.frontendTag}" }`
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Compare to another instance of `StabilityDeposit`.
80
+ */
81
+ equals(that: StabilityDeposit): boolean {
82
+ return (
83
+ this.initialZUSD.eq(that.initialZUSD) &&
84
+ this.currentZUSD.eq(that.currentZUSD) &&
85
+ this.collateralGain.eq(that.collateralGain) &&
86
+ this.zeroReward.eq(that.zeroReward) &&
87
+ this.frontendTag === that.frontendTag
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Calculate the difference between the `currentZUSD` in this Stability Deposit and `thatZUSD`.
93
+ *
94
+ * @returns An object representing the change, or `undefined` if the deposited amounts are equal.
95
+ */
96
+ whatChanged(thatZUSD: Decimalish): StabilityDepositChange<Decimal> | undefined {
97
+ thatZUSD = Decimal.from(thatZUSD);
98
+
99
+ if (thatZUSD.lt(this.currentZUSD)) {
100
+ return { withdrawZUSD: this.currentZUSD.sub(thatZUSD), withdrawAllZUSD: thatZUSD.isZero };
101
+ }
102
+
103
+ if (thatZUSD.gt(this.currentZUSD)) {
104
+ return { depositZUSD: thatZUSD.sub(this.currentZUSD) };
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Apply a {@link StabilityDepositChange} to this Stability Deposit.
110
+ *
111
+ * @returns The new deposited ZUSD amount.
112
+ */
113
+ apply(change: StabilityDepositChange<Decimalish> | undefined): Decimal {
114
+ if (!change) {
115
+ return this.currentZUSD;
116
+ }
117
+
118
+ if (change.withdrawZUSD !== undefined) {
119
+ return change.withdrawAllZUSD || this.currentZUSD.lte(change.withdrawZUSD)
120
+ ? Decimal.ZERO
121
+ : this.currentZUSD.sub(change.withdrawZUSD);
122
+ } else {
123
+ return this.currentZUSD.add(change.depositZUSD);
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,471 @@
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
+ /**
7
+ * Thrown by {@link TransactableLiquity} functions in case of transaction failure.
8
+ *
9
+ * @public
10
+ */
11
+ export class TransactionFailedError<T extends FailedReceipt = FailedReceipt> extends Error {
12
+ readonly failedReceipt: T;
13
+
14
+ /** @internal */
15
+ constructor(name: string, message: string, failedReceipt: T) {
16
+ super(message);
17
+ this.name = name;
18
+ this.failedReceipt = failedReceipt;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Details of an {@link TransactableLiquity.openTrove | openTrove()} transaction.
24
+ *
25
+ * @public
26
+ */
27
+ export interface TroveCreationDetails {
28
+ /** How much was deposited and borrowed. */
29
+ params: TroveCreationParams<Decimal>;
30
+
31
+ /** The Trove that was created by the transaction. */
32
+ newTrove: Trove;
33
+
34
+ /** Amount of ZUSD added to the Trove's debt as borrowing fee. */
35
+ fee: Decimal;
36
+ }
37
+
38
+ /**
39
+ * Details of an {@link TransactableLiquity.adjustTrove | adjustTrove()} transaction.
40
+ *
41
+ * @public
42
+ */
43
+ export interface TroveAdjustmentDetails {
44
+ /** Parameters of the adjustment. */
45
+ params: TroveAdjustmentParams<Decimal>;
46
+
47
+ /** New state of the adjusted Trove directly after the transaction. */
48
+ newTrove: Trove;
49
+
50
+ /** Amount of ZUSD added to the Trove's debt as borrowing fee. */
51
+ fee: Decimal;
52
+ }
53
+
54
+ /**
55
+ * Details of a {@link TransactableLiquity.closeTrove | closeTrove()} transaction.
56
+ *
57
+ * @public
58
+ */
59
+ export interface TroveClosureDetails {
60
+ /** How much was withdrawn and repaid. */
61
+ params: TroveClosureParams<Decimal>;
62
+ }
63
+
64
+ /**
65
+ * Details of a {@link TransactableLiquity.liquidate | liquidate()} or
66
+ * {@link TransactableLiquity.liquidateUpTo | liquidateUpTo()} transaction.
67
+ *
68
+ * @public
69
+ */
70
+ export interface LiquidationDetails {
71
+ /** Addresses whose Troves were liquidated by the transaction. */
72
+ liquidatedAddresses: string[];
73
+
74
+ /** Total collateral liquidated and debt cleared by the transaction. */
75
+ totalLiquidated: Trove;
76
+
77
+ /** Amount of ZUSD paid to the liquidator as gas compensation. */
78
+ zusdGasCompensation: Decimal;
79
+
80
+ /** Amount of native currency (e.g. Ether) paid to the liquidator as gas compensation. */
81
+ collateralGasCompensation: Decimal;
82
+ }
83
+
84
+ /**
85
+ * Details of a {@link TransactableLiquity.redeemZUSD | redeemZUSD()} transaction.
86
+ *
87
+ * @public
88
+ */
89
+ export interface RedemptionDetails {
90
+ /** Amount of ZUSD the redeemer tried to redeem. */
91
+ attemptedZUSDAmount: Decimal;
92
+
93
+ /**
94
+ * Amount of ZUSD that was actually redeemed by the transaction.
95
+ *
96
+ * @remarks
97
+ * This can end up being lower than `attemptedZUSDAmount` due to interference from another
98
+ * transaction that modifies the list of Troves.
99
+ *
100
+ * @public
101
+ */
102
+ actualZUSDAmount: Decimal;
103
+
104
+ /** Amount of collateral (e.g. Ether) taken from Troves by the transaction. */
105
+ collateralTaken: Decimal;
106
+
107
+ /** Amount of native currency (e.g. Ether) deducted as fee from collateral taken. */
108
+ fee: Decimal;
109
+ }
110
+
111
+ /**
112
+ * Details of a
113
+ * {@link TransactableLiquity.withdrawGainsFromStabilityPool | withdrawGainsFromStabilityPool()}
114
+ * transaction.
115
+ *
116
+ * @public
117
+ */
118
+ export interface StabilityPoolGainsWithdrawalDetails {
119
+ /** Amount of ZUSD burned from the deposit by liquidations since the last modification. */
120
+ zusdLoss: Decimal;
121
+
122
+ /** Amount of ZUSD in the deposit directly after this transaction. */
123
+ newZUSDDeposit: Decimal;
124
+
125
+ /** Amount of native currency (e.g. Ether) paid out to the depositor in this transaction. */
126
+ collateralGain: Decimal;
127
+
128
+ /** Amount of ZERO rewarded to the depositor in this transaction. */
129
+ zeroReward: Decimal;
130
+ }
131
+
132
+ /**
133
+ * Details of a
134
+ * {@link TransactableLiquity.depositZUSDInStabilityPool | depositZUSDInStabilityPool()} or
135
+ * {@link TransactableLiquity.withdrawZUSDFromStabilityPool | withdrawZUSDFromStabilityPool()}
136
+ * transaction.
137
+ *
138
+ * @public
139
+ */
140
+ export interface StabilityDepositChangeDetails extends StabilityPoolGainsWithdrawalDetails {
141
+ /** Change that was made to the deposit by this transaction. */
142
+ change: StabilityDepositChange<Decimal>;
143
+ }
144
+
145
+ /**
146
+ * Details of a
147
+ * {@link TransactableLiquity.transferCollateralGainToTrove | transferCollateralGainToTrove()}
148
+ * transaction.
149
+ *
150
+ * @public
151
+ */
152
+ export interface CollateralGainTransferDetails extends StabilityPoolGainsWithdrawalDetails {
153
+ /** New state of the depositor's Trove directly after the transaction. */
154
+ newTrove: Trove;
155
+ }
156
+
157
+ /**
158
+ * Send Zero transactions and wait for them to succeed.
159
+ *
160
+ * @remarks
161
+ * The functions return the details of the transaction (if any), or throw an implementation-specific
162
+ * subclass of {@link TransactionFailedError} in case of transaction failure.
163
+ *
164
+ * Implemented by {@link @sovryn-zero/lib-ethers#EthersLiquity}.
165
+ *
166
+ * @public
167
+ */
168
+ export interface TransactableLiquity {
169
+ /**
170
+ * Open a new Trove by depositing collateral and borrowing ZUSD.
171
+ *
172
+ * @param params - How much to deposit and borrow.
173
+ * @param maxBorrowingRate - Maximum acceptable
174
+ * {@link @sovryn-zero/lib-base#Fees.borrowingRate | borrowing rate}.
175
+ *
176
+ * @throws
177
+ * Throws {@link TransactionFailedError} in case of transaction failure.
178
+ *
179
+ * @remarks
180
+ * If `maxBorrowingRate` is omitted, the current borrowing rate plus 0.5% is used as maximum
181
+ * acceptable rate.
182
+ */
183
+ openTrove(
184
+ params: TroveCreationParams<Decimalish>,
185
+ maxBorrowingRate?: Decimalish
186
+ ): Promise<TroveCreationDetails>;
187
+
188
+ /**
189
+ * Close existing Trove by repaying all debt and withdrawing all collateral.
190
+ *
191
+ * @throws
192
+ * Throws {@link TransactionFailedError} in case of transaction failure.
193
+ */
194
+ closeTrove(): Promise<TroveClosureDetails>;
195
+
196
+ /**
197
+ * Adjust existing Trove by changing its collateral, debt, or both.
198
+ *
199
+ * @param params - Parameters of the adjustment.
200
+ * @param maxBorrowingRate - Maximum acceptable
201
+ * {@link @sovryn-zero/lib-base#Fees.borrowingRate | borrowing rate} if
202
+ * `params` includes `borrowZUSD`.
203
+ *
204
+ * @throws
205
+ * Throws {@link TransactionFailedError} in case of transaction failure.
206
+ *
207
+ * @remarks
208
+ * The transaction will fail if the Trove's debt would fall below
209
+ * {@link @sovryn-zero/lib-base#ZUSD_MINIMUM_DEBT}.
210
+ *
211
+ * If `maxBorrowingRate` is omitted, the current borrowing rate plus 0.5% is used as maximum
212
+ * acceptable rate.
213
+ */
214
+ adjustTrove(
215
+ params: TroveAdjustmentParams<Decimalish>,
216
+ maxBorrowingRate?: Decimalish
217
+ ): Promise<TroveAdjustmentDetails>;
218
+
219
+ /**
220
+ * Adjust existing Trove by depositing more collateral.
221
+ *
222
+ * @param amount - The amount of collateral to add to the Trove's existing collateral.
223
+ *
224
+ * @throws
225
+ * Throws {@link TransactionFailedError} in case of transaction failure.
226
+ *
227
+ * @remarks
228
+ * Equivalent to:
229
+ *
230
+ * ```typescript
231
+ * adjustTrove({ depositCollateral: amount })
232
+ * ```
233
+ */
234
+ depositCollateral(amount: Decimalish): Promise<TroveAdjustmentDetails>;
235
+
236
+ /**
237
+ * Adjust existing Trove by withdrawing some of its collateral.
238
+ *
239
+ * @param amount - The amount of collateral to withdraw from the Trove.
240
+ *
241
+ * @throws
242
+ * Throws {@link TransactionFailedError} in case of transaction failure.
243
+ *
244
+ * @remarks
245
+ * Equivalent to:
246
+ *
247
+ * ```typescript
248
+ * adjustTrove({ withdrawCollateral: amount })
249
+ * ```
250
+ */
251
+ withdrawCollateral(amount: Decimalish): Promise<TroveAdjustmentDetails>;
252
+
253
+ /**
254
+ * Adjust existing Trove by borrowing more ZUSD.
255
+ *
256
+ * @param amount - The amount of ZUSD to borrow.
257
+ * @param maxBorrowingRate - Maximum acceptable
258
+ * {@link @sovryn-zero/lib-base#Fees.borrowingRate | borrowing rate}.
259
+ *
260
+ * @throws
261
+ * Throws {@link TransactionFailedError} in case of transaction failure.
262
+ *
263
+ * @remarks
264
+ * Equivalent to:
265
+ *
266
+ * ```typescript
267
+ * adjustTrove({ borrowZUSD: amount }, maxBorrowingRate)
268
+ * ```
269
+ */
270
+ borrowZUSD(amount: Decimalish, maxBorrowingRate?: Decimalish): Promise<TroveAdjustmentDetails>;
271
+
272
+ /**
273
+ * Adjust existing Trove by repaying some of its debt.
274
+ *
275
+ * @param amount - The amount of ZUSD to repay.
276
+ *
277
+ * @throws
278
+ * Throws {@link TransactionFailedError} in case of transaction failure.
279
+ *
280
+ * @remarks
281
+ * Equivalent to:
282
+ *
283
+ * ```typescript
284
+ * adjustTrove({ repayZUSD: amount })
285
+ * ```
286
+ */
287
+ repayZUSD(amount: Decimalish): Promise<TroveAdjustmentDetails>;
288
+
289
+ /** @internal */
290
+ setPrice(price: Decimalish): Promise<void>;
291
+
292
+ /**
293
+ * Liquidate one or more undercollateralized Troves.
294
+ *
295
+ * @param address - Address or array of addresses whose Troves to liquidate.
296
+ *
297
+ * @throws
298
+ * Throws {@link TransactionFailedError} in case of transaction failure.
299
+ */
300
+ liquidate(address: string | string[]): Promise<LiquidationDetails>;
301
+
302
+ /**
303
+ * Liquidate the least collateralized Troves up to a maximum number.
304
+ *
305
+ * @param maximumNumberOfTrovesToLiquidate - Stop after liquidating this many Troves.
306
+ *
307
+ * @throws
308
+ * Throws {@link TransactionFailedError} in case of transaction failure.
309
+ */
310
+ liquidateUpTo(maximumNumberOfTrovesToLiquidate: number): Promise<LiquidationDetails>;
311
+
312
+ /**
313
+ * Make a new Stability Deposit, or top up existing one.
314
+ *
315
+ * @param amount - Amount of ZUSD to add to new or existing deposit.
316
+ * @param frontendTag - Address that should receive a share of this deposit's ZERO rewards.
317
+ *
318
+ * @throws
319
+ * Throws {@link TransactionFailedError} in case of transaction failure.
320
+ *
321
+ * @remarks
322
+ * The `frontendTag` parameter is only effective when making a new deposit.
323
+ *
324
+ * As a side-effect, the transaction will also pay out an existing Stability Deposit's
325
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} and
326
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward}.
327
+ */
328
+ depositZUSDInStabilityPool(
329
+ amount: Decimalish,
330
+ frontendTag?: string
331
+ ): Promise<StabilityDepositChangeDetails>;
332
+
333
+ /**
334
+ * Withdraw ZUSD from Stability Deposit.
335
+ *
336
+ * @param amount - Amount of ZUSD to withdraw.
337
+ *
338
+ * @throws
339
+ * Throws {@link TransactionFailedError} in case of transaction failure.
340
+ *
341
+ * @remarks
342
+ * As a side-effect, the transaction will also pay out the Stability Deposit's
343
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} and
344
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward}.
345
+ */
346
+ withdrawZUSDFromStabilityPool(amount: Decimalish): Promise<StabilityDepositChangeDetails>;
347
+
348
+ /**
349
+ * Withdraw {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} and
350
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward} from Stability Deposit.
351
+ *
352
+ * @throws
353
+ * Throws {@link TransactionFailedError} in case of transaction failure.
354
+ */
355
+ withdrawGainsFromStabilityPool(): Promise<StabilityPoolGainsWithdrawalDetails>;
356
+
357
+ /**
358
+ * Transfer {@link @sovryn-zero/lib-base#StabilityDeposit.collateralGain | collateral gain} from
359
+ * Stability Deposit to Trove.
360
+ *
361
+ * @throws
362
+ * Throws {@link TransactionFailedError} in case of transaction failure.
363
+ *
364
+ * @remarks
365
+ * The collateral gain is transfered to the Trove as additional collateral.
366
+ *
367
+ * As a side-effect, the transaction will also pay out the Stability Deposit's
368
+ * {@link @sovryn-zero/lib-base#StabilityDeposit.zeroReward | ZERO reward}.
369
+ */
370
+ transferCollateralGainToTrove(): Promise<CollateralGainTransferDetails>;
371
+
372
+ /**
373
+ * Send ZUSD tokens to an address.
374
+ *
375
+ * @param toAddress - Address of receipient.
376
+ * @param amount - Amount of ZUSD to send.
377
+ *
378
+ * @throws
379
+ * Throws {@link TransactionFailedError} in case of transaction failure.
380
+ */
381
+ sendZUSD(toAddress: string, amount: Decimalish): Promise<void>;
382
+
383
+ /**
384
+ * Send ZERO tokens to an address.
385
+ *
386
+ * @param toAddress - Address of receipient.
387
+ * @param amount - Amount of ZERO to send.
388
+ *
389
+ * @throws
390
+ * Throws {@link TransactionFailedError} in case of transaction failure.
391
+ */
392
+ sendZERO(toAddress: string, amount: Decimalish): Promise<void>;
393
+
394
+ /**
395
+ * Redeem ZUSD to native currency (e.g. Ether) at face value.
396
+ *
397
+ * @param amount - Amount of ZUSD to be redeemed.
398
+ * @param maxRedemptionRate - Maximum acceptable
399
+ * {@link @sovryn-zero/lib-base#Fees.redemptionRate | redemption rate}.
400
+ *
401
+ * @throws
402
+ * Throws {@link TransactionFailedError} in case of transaction failure.
403
+ *
404
+ * @remarks
405
+ * If `maxRedemptionRate` is omitted, the current redemption rate (based on `amount`) plus 0.1%
406
+ * is used as maximum acceptable rate.
407
+ */
408
+ redeemZUSD(amount: Decimalish, maxRedemptionRate?: Decimalish): Promise<RedemptionDetails>;
409
+
410
+ /**
411
+ * Claim leftover collateral after a liquidation or redemption.
412
+ *
413
+ * @remarks
414
+ * Use {@link @sovryn-zero/lib-base#ReadableLiquity.getCollateralSurplusBalance | getCollateralSurplusBalance()}
415
+ * to check the amount of collateral available for withdrawal.
416
+ *
417
+ * @throws
418
+ * Throws {@link TransactionFailedError} in case of transaction failure.
419
+ */
420
+ claimCollateralSurplus(): Promise<void>;
421
+
422
+ /**
423
+ * Stake ZERO to start earning fee revenue or increase existing stake.
424
+ *
425
+ * @param amount - Amount of ZERO to add to new or existing stake.
426
+ *
427
+ * @throws
428
+ * Throws {@link TransactionFailedError} in case of transaction failure.
429
+ *
430
+ * @remarks
431
+ * As a side-effect, the transaction will also pay out an existing ZERO stake's
432
+ * {@link @sovryn-zero/lib-base#ZEROStake.collateralGain | collateral gain} and
433
+ * {@link @sovryn-zero/lib-base#ZEROStake.zusdGain | ZUSD gain}.
434
+ */
435
+ stakeZERO(amount: Decimalish): Promise<void>;
436
+
437
+ /**
438
+ * Withdraw ZERO from staking.
439
+ *
440
+ * @param amount - Amount of ZERO to withdraw.
441
+ *
442
+ * @throws
443
+ * Throws {@link TransactionFailedError} in case of transaction failure.
444
+ *
445
+ * @remarks
446
+ * As a side-effect, the transaction will also pay out the ZERO stake's
447
+ * {@link @sovryn-zero/lib-base#ZEROStake.collateralGain | collateral gain} and
448
+ * {@link @sovryn-zero/lib-base#ZEROStake.zusdGain | ZUSD gain}.
449
+ */
450
+ unstakeZERO(amount: Decimalish): Promise<void>;
451
+
452
+ /**
453
+ * Withdraw {@link @sovryn-zero/lib-base#ZEROStake.collateralGain | collateral gain} and
454
+ * {@link @sovryn-zero/lib-base#ZEROStake.zusdGain | ZUSD gain} from ZERO stake.
455
+ *
456
+ * @throws
457
+ * Throws {@link TransactionFailedError} in case of transaction failure.
458
+ */
459
+ withdrawGainsFromStaking(): Promise<void>;
460
+
461
+ /**
462
+ * Register current wallet address as a Zero frontend.
463
+ *
464
+ * @param kickbackRate - The portion of ZERO rewards to pass onto users of the frontend
465
+ * (between 0 and 1).
466
+ *
467
+ * @throws
468
+ * Throws {@link TransactionFailedError} in case of transaction failure.
469
+ */
470
+ registerFrontend(kickbackRate: Decimalish): Promise<void>;
471
+ }