@sovryn-zero/lib-base 0.1.0 → 0.2.1

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.
@@ -1,156 +1,156 @@
1
- import { Decimalish } from "./Decimal";
2
- import { TroveAdjustmentParams, TroveCreationParams } from "./Trove";
3
- import { CollateralGainTransferDetails, LiquidationDetails, RedemptionDetails, StabilityDepositChangeDetails, StabilityPoolGainsWithdrawalDetails, TransactableLiquity, TroveAdjustmentDetails, TroveClosureDetails, TroveCreationDetails } from "./TransactableLiquity";
4
- /**
5
- * A transaction that has already been sent.
6
- *
7
- * @remarks
8
- * Implemented by {@link @sovryn-zero/lib-ethers#SentEthersLiquityTransaction}.
9
- *
10
- * @public
11
- */
12
- export interface SentLiquityTransaction<S = unknown, T extends LiquityReceipt = LiquityReceipt> {
13
- /** Implementation-specific sent transaction object. */
14
- readonly rawSentTransaction: S;
15
- /**
16
- * Check whether the transaction has been mined, and whether it was successful.
17
- *
18
- * @remarks
19
- * Unlike {@link @sovryn-zero/lib-base#SentLiquityTransaction.waitForReceipt | waitForReceipt()},
20
- * this function doesn't wait for the transaction to be mined.
21
- */
22
- getReceipt(): Promise<T>;
23
- /**
24
- * Wait for the transaction to be mined, and check whether it was successful.
25
- *
26
- * @returns Either a {@link @sovryn-zero/lib-base#FailedReceipt} or a
27
- * {@link @sovryn-zero/lib-base#SuccessfulReceipt}.
28
- */
29
- waitForReceipt(): Promise<Extract<T, MinedReceipt>>;
30
- }
31
- /**
32
- * Indicates that the transaction hasn't been mined yet.
33
- *
34
- * @remarks
35
- * Returned by {@link SentLiquityTransaction.getReceipt}.
36
- *
37
- * @public
38
- */
39
- export declare type PendingReceipt = {
40
- status: "pending";
41
- };
42
- /** @internal */
43
- export declare const _pendingReceipt: PendingReceipt;
44
- /**
45
- * Indicates that the transaction has been mined, but it failed.
46
- *
47
- * @remarks
48
- * The `rawReceipt` property is an implementation-specific transaction receipt object.
49
- *
50
- * Returned by {@link SentLiquityTransaction.getReceipt} and
51
- * {@link SentLiquityTransaction.waitForReceipt}.
52
- *
53
- * @public
54
- */
55
- export declare type FailedReceipt<R = unknown> = {
56
- status: "failed";
57
- rawReceipt: R;
58
- };
59
- /** @internal */
60
- export declare const _failedReceipt: <R>(rawReceipt: R) => FailedReceipt<R>;
61
- /**
62
- * Indicates that the transaction has succeeded.
63
- *
64
- * @remarks
65
- * The `rawReceipt` property is an implementation-specific transaction receipt object.
66
- *
67
- * The `details` property may contain more information about the transaction.
68
- * See the return types of {@link TransactableLiquity} functions for the exact contents of `details`
69
- * for each type of Zero transaction.
70
- *
71
- * Returned by {@link SentLiquityTransaction.getReceipt} and
72
- * {@link SentLiquityTransaction.waitForReceipt}.
73
- *
74
- * @public
75
- */
76
- export declare type SuccessfulReceipt<R = unknown, D = unknown> = {
77
- status: "succeeded";
78
- rawReceipt: R;
79
- details: D;
80
- };
81
- /** @internal */
82
- export declare const _successfulReceipt: <R, D>(rawReceipt: R, details: D, toString?: (() => string) | undefined) => SuccessfulReceipt<R, D>;
83
- /**
84
- * Either a {@link FailedReceipt} or a {@link SuccessfulReceipt}.
85
- *
86
- * @public
87
- */
88
- export declare type MinedReceipt<R = unknown, D = unknown> = FailedReceipt<R> | SuccessfulReceipt<R, D>;
89
- /**
90
- * One of either a {@link PendingReceipt}, a {@link FailedReceipt} or a {@link SuccessfulReceipt}.
91
- *
92
- * @public
93
- */
94
- export declare type LiquityReceipt<R = unknown, D = unknown> = PendingReceipt | MinedReceipt<R, D>;
95
- /** @internal */
96
- export declare type _SendableFrom<T, R, S> = {
97
- [M in keyof T]: T[M] extends (...args: infer A) => Promise<infer D> ? (...args: A) => Promise<SentLiquityTransaction<S, LiquityReceipt<R, D>>> : never;
98
- };
99
- /**
100
- * Send Zero transactions.
101
- *
102
- * @remarks
103
- * The functions return an object implementing {@link SentLiquityTransaction}, which can be used
104
- * to monitor the transaction and get its details when it succeeds.
105
- *
106
- * Implemented by {@link @sovryn-zero/lib-ethers#SendableEthersLiquity}.
107
- *
108
- * @public
109
- */
110
- export interface SendableLiquity<R = unknown, S = unknown> extends _SendableFrom<TransactableLiquity, R, S> {
111
- /** {@inheritDoc TransactableLiquity.openTrove} */
112
- openTrove(params: TroveCreationParams<Decimalish>, maxBorrowingRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveCreationDetails>>>;
113
- /** {@inheritDoc TransactableLiquity.closeTrove} */
114
- closeTrove(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveClosureDetails>>>;
115
- /** {@inheritDoc TransactableLiquity.adjustTrove} */
116
- adjustTrove(params: TroveAdjustmentParams<Decimalish>, maxBorrowingRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
117
- /** {@inheritDoc TransactableLiquity.depositCollateral} */
118
- depositCollateral(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
119
- /** {@inheritDoc TransactableLiquity.withdrawCollateral} */
120
- withdrawCollateral(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
121
- /** {@inheritDoc TransactableLiquity.borrowZUSD} */
122
- borrowZUSD(amount: Decimalish, maxBorrowingRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
123
- /** {@inheritDoc TransactableLiquity.repayZUSD} */
124
- repayZUSD(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
125
- /** @internal */
126
- setPrice(price: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
127
- /** {@inheritDoc TransactableLiquity.liquidate} */
128
- liquidate(address: string | string[]): Promise<SentLiquityTransaction<S, LiquityReceipt<R, LiquidationDetails>>>;
129
- /** {@inheritDoc TransactableLiquity.liquidateUpTo} */
130
- liquidateUpTo(maximumNumberOfTrovesToLiquidate: number): Promise<SentLiquityTransaction<S, LiquityReceipt<R, LiquidationDetails>>>;
131
- /** {@inheritDoc TransactableLiquity.depositZUSDInStabilityPool} */
132
- depositZUSDInStabilityPool(amount: Decimalish, frontendTag?: string): Promise<SentLiquityTransaction<S, LiquityReceipt<R, StabilityDepositChangeDetails>>>;
133
- /** {@inheritDoc TransactableLiquity.withdrawZUSDFromStabilityPool} */
134
- withdrawZUSDFromStabilityPool(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, StabilityDepositChangeDetails>>>;
135
- /** {@inheritDoc TransactableLiquity.withdrawGainsFromStabilityPool} */
136
- withdrawGainsFromStabilityPool(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, StabilityPoolGainsWithdrawalDetails>>>;
137
- /** {@inheritDoc TransactableLiquity.transferCollateralGainToTrove} */
138
- transferCollateralGainToTrove(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, CollateralGainTransferDetails>>>;
139
- /** {@inheritDoc TransactableLiquity.sendZUSD} */
140
- sendZUSD(toAddress: string, amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
141
- /** {@inheritDoc TransactableLiquity.sendZERO} */
142
- sendZERO(toAddress: string, amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
143
- /** {@inheritDoc TransactableLiquity.redeemZUSD} */
144
- redeemZUSD(amount: Decimalish, maxRedemptionRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, RedemptionDetails>>>;
145
- /** {@inheritDoc TransactableLiquity.claimCollateralSurplus} */
146
- claimCollateralSurplus(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
147
- /** {@inheritDoc TransactableLiquity.stakeZERO} */
148
- stakeZERO(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
149
- /** {@inheritDoc TransactableLiquity.unstakeZERO} */
150
- unstakeZERO(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
151
- /** {@inheritDoc TransactableLiquity.withdrawGainsFromStaking} */
152
- withdrawGainsFromStaking(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
153
- /** {@inheritDoc TransactableLiquity.registerFrontend} */
154
- registerFrontend(kickbackRate: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
155
- }
1
+ import { Decimalish } from "./Decimal";
2
+ import { TroveAdjustmentParams, TroveCreationParams } from "./Trove";
3
+ import { CollateralGainTransferDetails, LiquidationDetails, RedemptionDetails, StabilityDepositChangeDetails, StabilityPoolGainsWithdrawalDetails, TransactableLiquity, TroveAdjustmentDetails, TroveClosureDetails, TroveCreationDetails } from "./TransactableLiquity";
4
+ /**
5
+ * A transaction that has already been sent.
6
+ *
7
+ * @remarks
8
+ * Implemented by {@link @sovryn-zero/lib-ethers#SentEthersLiquityTransaction}.
9
+ *
10
+ * @public
11
+ */
12
+ export interface SentLiquityTransaction<S = unknown, T extends LiquityReceipt = LiquityReceipt> {
13
+ /** Implementation-specific sent transaction object. */
14
+ readonly rawSentTransaction: S;
15
+ /**
16
+ * Check whether the transaction has been mined, and whether it was successful.
17
+ *
18
+ * @remarks
19
+ * Unlike {@link @sovryn-zero/lib-base#SentLiquityTransaction.waitForReceipt | waitForReceipt()},
20
+ * this function doesn't wait for the transaction to be mined.
21
+ */
22
+ getReceipt(): Promise<T>;
23
+ /**
24
+ * Wait for the transaction to be mined, and check whether it was successful.
25
+ *
26
+ * @returns Either a {@link @sovryn-zero/lib-base#FailedReceipt} or a
27
+ * {@link @sovryn-zero/lib-base#SuccessfulReceipt}.
28
+ */
29
+ waitForReceipt(): Promise<Extract<T, MinedReceipt>>;
30
+ }
31
+ /**
32
+ * Indicates that the transaction hasn't been mined yet.
33
+ *
34
+ * @remarks
35
+ * Returned by {@link SentLiquityTransaction.getReceipt}.
36
+ *
37
+ * @public
38
+ */
39
+ export declare type PendingReceipt = {
40
+ status: "pending";
41
+ };
42
+ /** @internal */
43
+ export declare const _pendingReceipt: PendingReceipt;
44
+ /**
45
+ * Indicates that the transaction has been mined, but it failed.
46
+ *
47
+ * @remarks
48
+ * The `rawReceipt` property is an implementation-specific transaction receipt object.
49
+ *
50
+ * Returned by {@link SentLiquityTransaction.getReceipt} and
51
+ * {@link SentLiquityTransaction.waitForReceipt}.
52
+ *
53
+ * @public
54
+ */
55
+ export declare type FailedReceipt<R = unknown> = {
56
+ status: "failed";
57
+ rawReceipt: R;
58
+ };
59
+ /** @internal */
60
+ export declare const _failedReceipt: <R>(rawReceipt: R) => FailedReceipt<R>;
61
+ /**
62
+ * Indicates that the transaction has succeeded.
63
+ *
64
+ * @remarks
65
+ * The `rawReceipt` property is an implementation-specific transaction receipt object.
66
+ *
67
+ * The `details` property may contain more information about the transaction.
68
+ * See the return types of {@link TransactableLiquity} functions for the exact contents of `details`
69
+ * for each type of Zero transaction.
70
+ *
71
+ * Returned by {@link SentLiquityTransaction.getReceipt} and
72
+ * {@link SentLiquityTransaction.waitForReceipt}.
73
+ *
74
+ * @public
75
+ */
76
+ export declare type SuccessfulReceipt<R = unknown, D = unknown> = {
77
+ status: "succeeded";
78
+ rawReceipt: R;
79
+ details: D;
80
+ };
81
+ /** @internal */
82
+ export declare const _successfulReceipt: <R, D>(rawReceipt: R, details: D, toString?: (() => string) | undefined) => SuccessfulReceipt<R, D>;
83
+ /**
84
+ * Either a {@link FailedReceipt} or a {@link SuccessfulReceipt}.
85
+ *
86
+ * @public
87
+ */
88
+ export declare type MinedReceipt<R = unknown, D = unknown> = FailedReceipt<R> | SuccessfulReceipt<R, D>;
89
+ /**
90
+ * One of either a {@link PendingReceipt}, a {@link FailedReceipt} or a {@link SuccessfulReceipt}.
91
+ *
92
+ * @public
93
+ */
94
+ export declare type LiquityReceipt<R = unknown, D = unknown> = PendingReceipt | MinedReceipt<R, D>;
95
+ /** @internal */
96
+ export declare type _SendableFrom<T, R, S> = {
97
+ [M in keyof T]: T[M] extends (...args: infer A) => Promise<infer D> ? (...args: A) => Promise<SentLiquityTransaction<S, LiquityReceipt<R, D>>> : never;
98
+ };
99
+ /**
100
+ * Send Zero transactions.
101
+ *
102
+ * @remarks
103
+ * The functions return an object implementing {@link SentLiquityTransaction}, which can be used
104
+ * to monitor the transaction and get its details when it succeeds.
105
+ *
106
+ * Implemented by {@link @sovryn-zero/lib-ethers#SendableEthersLiquity}.
107
+ *
108
+ * @public
109
+ */
110
+ export interface SendableLiquity<R = unknown, S = unknown> extends _SendableFrom<TransactableLiquity, R, S> {
111
+ /** {@inheritDoc TransactableLiquity.openTrove} */
112
+ openTrove(params: TroveCreationParams<Decimalish>, maxBorrowingRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveCreationDetails>>>;
113
+ /** {@inheritDoc TransactableLiquity.closeTrove} */
114
+ closeTrove(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveClosureDetails>>>;
115
+ /** {@inheritDoc TransactableLiquity.adjustTrove} */
116
+ adjustTrove(params: TroveAdjustmentParams<Decimalish>, maxBorrowingRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
117
+ /** {@inheritDoc TransactableLiquity.depositCollateral} */
118
+ depositCollateral(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
119
+ /** {@inheritDoc TransactableLiquity.withdrawCollateral} */
120
+ withdrawCollateral(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
121
+ /** {@inheritDoc TransactableLiquity.borrowZUSD} */
122
+ borrowZUSD(amount: Decimalish, maxBorrowingRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
123
+ /** {@inheritDoc TransactableLiquity.repayZUSD} */
124
+ repayZUSD(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, TroveAdjustmentDetails>>>;
125
+ /** @internal */
126
+ setPrice(price: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
127
+ /** {@inheritDoc TransactableLiquity.liquidate} */
128
+ liquidate(address: string | string[]): Promise<SentLiquityTransaction<S, LiquityReceipt<R, LiquidationDetails>>>;
129
+ /** {@inheritDoc TransactableLiquity.liquidateUpTo} */
130
+ liquidateUpTo(maximumNumberOfTrovesToLiquidate: number): Promise<SentLiquityTransaction<S, LiquityReceipt<R, LiquidationDetails>>>;
131
+ /** {@inheritDoc TransactableLiquity.depositZUSDInStabilityPool} */
132
+ depositZUSDInStabilityPool(amount: Decimalish, frontendTag?: string): Promise<SentLiquityTransaction<S, LiquityReceipt<R, StabilityDepositChangeDetails>>>;
133
+ /** {@inheritDoc TransactableLiquity.withdrawZUSDFromStabilityPool} */
134
+ withdrawZUSDFromStabilityPool(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, StabilityDepositChangeDetails>>>;
135
+ /** {@inheritDoc TransactableLiquity.withdrawGainsFromStabilityPool} */
136
+ withdrawGainsFromStabilityPool(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, StabilityPoolGainsWithdrawalDetails>>>;
137
+ /** {@inheritDoc TransactableLiquity.transferCollateralGainToTrove} */
138
+ transferCollateralGainToTrove(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, CollateralGainTransferDetails>>>;
139
+ /** {@inheritDoc TransactableLiquity.sendZUSD} */
140
+ sendZUSD(toAddress: string, amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
141
+ /** {@inheritDoc TransactableLiquity.sendZERO} */
142
+ sendZERO(toAddress: string, amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
143
+ /** {@inheritDoc TransactableLiquity.redeemZUSD} */
144
+ redeemZUSD(amount: Decimalish, maxRedemptionRate?: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, RedemptionDetails>>>;
145
+ /** {@inheritDoc TransactableLiquity.claimCollateralSurplus} */
146
+ claimCollateralSurplus(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
147
+ /** {@inheritDoc TransactableLiquity.stakeZERO} */
148
+ stakeZERO(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
149
+ /** {@inheritDoc TransactableLiquity.unstakeZERO} */
150
+ unstakeZERO(amount: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
151
+ /** {@inheritDoc TransactableLiquity.withdrawGainsFromStaking} */
152
+ withdrawGainsFromStaking(): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
153
+ /** {@inheritDoc TransactableLiquity.registerFrontend} */
154
+ registerFrontend(kickbackRate: Decimalish): Promise<SentLiquityTransaction<S, LiquityReceipt<R, void>>>;
155
+ }
156
156
  //# sourceMappingURL=SendableLiquity.d.ts.map
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._successfulReceipt = exports._failedReceipt = exports._pendingReceipt = void 0;
4
- /** @internal */
5
- exports._pendingReceipt = { status: "pending" };
6
- /** @internal */
7
- const _failedReceipt = (rawReceipt) => ({
8
- status: "failed",
9
- rawReceipt
10
- });
11
- exports._failedReceipt = _failedReceipt;
12
- /** @internal */
13
- const _successfulReceipt = (rawReceipt, details, toString) => ({
14
- status: "succeeded",
15
- rawReceipt,
16
- details,
17
- ...(toString ? { toString } : {})
18
- });
19
- exports._successfulReceipt = _successfulReceipt;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._successfulReceipt = exports._failedReceipt = exports._pendingReceipt = void 0;
4
+ /** @internal */
5
+ exports._pendingReceipt = { status: "pending" };
6
+ /** @internal */
7
+ const _failedReceipt = (rawReceipt) => ({
8
+ status: "failed",
9
+ rawReceipt
10
+ });
11
+ exports._failedReceipt = _failedReceipt;
12
+ /** @internal */
13
+ const _successfulReceipt = (rawReceipt, details, toString) => ({
14
+ status: "succeeded",
15
+ rawReceipt,
16
+ details,
17
+ ...(toString ? { toString } : {})
18
+ });
19
+ exports._successfulReceipt = _successfulReceipt;
20
20
  //# sourceMappingURL=SendableLiquity.js.map
@@ -1,59 +1,59 @@
1
- import { Decimal, Decimalish } from "./Decimal";
2
- /**
3
- * Represents the change between two Stability Deposit states.
4
- *
5
- * @public
6
- */
7
- export declare type StabilityDepositChange<T> = {
8
- depositZUSD: T;
9
- withdrawZUSD?: undefined;
10
- } | {
11
- depositZUSD?: undefined;
12
- withdrawZUSD: T;
13
- withdrawAllZUSD: boolean;
14
- };
15
- /**
16
- * A Stability Deposit and its accrued gains.
17
- *
18
- * @public
19
- */
20
- export declare class StabilityDeposit {
21
- /** Amount of ZUSD in the Stability Deposit at the time of the last direct modification. */
22
- readonly initialZUSD: Decimal;
23
- /** Amount of ZUSD left in the Stability Deposit. */
24
- readonly currentZUSD: Decimal;
25
- /** Amount of native currency (e.g. Ether) received in exchange for the used-up ZUSD. */
26
- readonly collateralGain: Decimal;
27
- /** Amount of ZERO rewarded since the last modification of the Stability Deposit. */
28
- readonly zeroReward: Decimal;
29
- /**
30
- * Address of frontend through which this Stability Deposit was made.
31
- *
32
- * @remarks
33
- * If the Stability Deposit was made through a frontend that doesn't tag deposits, this will be
34
- * the zero-address.
35
- */
36
- readonly frontendTag: string;
37
- /** @internal */
38
- constructor(initialZUSD: Decimal, currentZUSD: Decimal, collateralGain: Decimal, zeroReward: Decimal, frontendTag: string);
39
- get isEmpty(): boolean;
40
- /** @internal */
41
- toString(): string;
42
- /**
43
- * Compare to another instance of `StabilityDeposit`.
44
- */
45
- equals(that: StabilityDeposit): boolean;
46
- /**
47
- * Calculate the difference between the `currentZUSD` in this Stability Deposit and `thatZUSD`.
48
- *
49
- * @returns An object representing the change, or `undefined` if the deposited amounts are equal.
50
- */
51
- whatChanged(thatZUSD: Decimalish): StabilityDepositChange<Decimal> | undefined;
52
- /**
53
- * Apply a {@link StabilityDepositChange} to this Stability Deposit.
54
- *
55
- * @returns The new deposited ZUSD amount.
56
- */
57
- apply(change: StabilityDepositChange<Decimalish> | undefined): Decimal;
58
- }
1
+ import { Decimal, Decimalish } from "./Decimal";
2
+ /**
3
+ * Represents the change between two Stability Deposit states.
4
+ *
5
+ * @public
6
+ */
7
+ export declare type StabilityDepositChange<T> = {
8
+ depositZUSD: T;
9
+ withdrawZUSD?: undefined;
10
+ } | {
11
+ depositZUSD?: undefined;
12
+ withdrawZUSD: T;
13
+ withdrawAllZUSD: boolean;
14
+ };
15
+ /**
16
+ * A Stability Deposit and its accrued gains.
17
+ *
18
+ * @public
19
+ */
20
+ export declare class StabilityDeposit {
21
+ /** Amount of ZUSD in the Stability Deposit at the time of the last direct modification. */
22
+ readonly initialZUSD: Decimal;
23
+ /** Amount of ZUSD left in the Stability Deposit. */
24
+ readonly currentZUSD: Decimal;
25
+ /** Amount of native currency (e.g. Ether) received in exchange for the used-up ZUSD. */
26
+ readonly collateralGain: Decimal;
27
+ /** Amount of ZERO rewarded since the last modification of the Stability Deposit. */
28
+ readonly zeroReward: Decimal;
29
+ /**
30
+ * Address of frontend through which this Stability Deposit was made.
31
+ *
32
+ * @remarks
33
+ * If the Stability Deposit was made through a frontend that doesn't tag deposits, this will be
34
+ * the zero-address.
35
+ */
36
+ readonly frontendTag: string;
37
+ /** @internal */
38
+ constructor(initialZUSD: Decimal, currentZUSD: Decimal, collateralGain: Decimal, zeroReward: Decimal, frontendTag: string);
39
+ get isEmpty(): boolean;
40
+ /** @internal */
41
+ toString(): string;
42
+ /**
43
+ * Compare to another instance of `StabilityDeposit`.
44
+ */
45
+ equals(that: StabilityDeposit): boolean;
46
+ /**
47
+ * Calculate the difference between the `currentZUSD` in this Stability Deposit and `thatZUSD`.
48
+ *
49
+ * @returns An object representing the change, or `undefined` if the deposited amounts are equal.
50
+ */
51
+ whatChanged(thatZUSD: Decimalish): StabilityDepositChange<Decimal> | undefined;
52
+ /**
53
+ * Apply a {@link StabilityDepositChange} to this Stability Deposit.
54
+ *
55
+ * @returns The new deposited ZUSD amount.
56
+ */
57
+ apply(change: StabilityDepositChange<Decimalish> | undefined): Decimal;
58
+ }
59
59
  //# sourceMappingURL=StabilityDeposit.d.ts.map
@@ -1,80 +1,80 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StabilityDeposit = void 0;
4
- const Decimal_1 = require("./Decimal");
5
- /**
6
- * A Stability Deposit and its accrued gains.
7
- *
8
- * @public
9
- */
10
- class StabilityDeposit {
11
- /** @internal */
12
- constructor(initialZUSD, currentZUSD, collateralGain, zeroReward, frontendTag) {
13
- this.initialZUSD = initialZUSD;
14
- this.currentZUSD = currentZUSD;
15
- this.collateralGain = collateralGain;
16
- this.zeroReward = zeroReward;
17
- this.frontendTag = frontendTag;
18
- if (this.currentZUSD.gt(this.initialZUSD)) {
19
- throw new Error("currentZUSD can't be greater than initialZUSD");
20
- }
21
- }
22
- get isEmpty() {
23
- return (this.initialZUSD.isZero &&
24
- this.currentZUSD.isZero &&
25
- this.collateralGain.isZero &&
26
- this.zeroReward.isZero);
27
- }
28
- /** @internal */
29
- toString() {
30
- return (`{ initialZUSD: ${this.initialZUSD}` +
31
- `, currentZUSD: ${this.currentZUSD}` +
32
- `, collateralGain: ${this.collateralGain}` +
33
- `, zeroReward: ${this.zeroReward}` +
34
- `, frontendTag: "${this.frontendTag}" }`);
35
- }
36
- /**
37
- * Compare to another instance of `StabilityDeposit`.
38
- */
39
- equals(that) {
40
- return (this.initialZUSD.eq(that.initialZUSD) &&
41
- this.currentZUSD.eq(that.currentZUSD) &&
42
- this.collateralGain.eq(that.collateralGain) &&
43
- this.zeroReward.eq(that.zeroReward) &&
44
- this.frontendTag === that.frontendTag);
45
- }
46
- /**
47
- * Calculate the difference between the `currentZUSD` in this Stability Deposit and `thatZUSD`.
48
- *
49
- * @returns An object representing the change, or `undefined` if the deposited amounts are equal.
50
- */
51
- whatChanged(thatZUSD) {
52
- thatZUSD = Decimal_1.Decimal.from(thatZUSD);
53
- if (thatZUSD.lt(this.currentZUSD)) {
54
- return { withdrawZUSD: this.currentZUSD.sub(thatZUSD), withdrawAllZUSD: thatZUSD.isZero };
55
- }
56
- if (thatZUSD.gt(this.currentZUSD)) {
57
- return { depositZUSD: thatZUSD.sub(this.currentZUSD) };
58
- }
59
- }
60
- /**
61
- * Apply a {@link StabilityDepositChange} to this Stability Deposit.
62
- *
63
- * @returns The new deposited ZUSD amount.
64
- */
65
- apply(change) {
66
- if (!change) {
67
- return this.currentZUSD;
68
- }
69
- if (change.withdrawZUSD !== undefined) {
70
- return change.withdrawAllZUSD || this.currentZUSD.lte(change.withdrawZUSD)
71
- ? Decimal_1.Decimal.ZERO
72
- : this.currentZUSD.sub(change.withdrawZUSD);
73
- }
74
- else {
75
- return this.currentZUSD.add(change.depositZUSD);
76
- }
77
- }
78
- }
79
- exports.StabilityDeposit = StabilityDeposit;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StabilityDeposit = void 0;
4
+ const Decimal_1 = require("./Decimal");
5
+ /**
6
+ * A Stability Deposit and its accrued gains.
7
+ *
8
+ * @public
9
+ */
10
+ class StabilityDeposit {
11
+ /** @internal */
12
+ constructor(initialZUSD, currentZUSD, collateralGain, zeroReward, frontendTag) {
13
+ this.initialZUSD = initialZUSD;
14
+ this.currentZUSD = currentZUSD;
15
+ this.collateralGain = collateralGain;
16
+ this.zeroReward = zeroReward;
17
+ this.frontendTag = frontendTag;
18
+ if (this.currentZUSD.gt(this.initialZUSD)) {
19
+ throw new Error("currentZUSD can't be greater than initialZUSD");
20
+ }
21
+ }
22
+ get isEmpty() {
23
+ return (this.initialZUSD.isZero &&
24
+ this.currentZUSD.isZero &&
25
+ this.collateralGain.isZero &&
26
+ this.zeroReward.isZero);
27
+ }
28
+ /** @internal */
29
+ toString() {
30
+ return (`{ initialZUSD: ${this.initialZUSD}` +
31
+ `, currentZUSD: ${this.currentZUSD}` +
32
+ `, collateralGain: ${this.collateralGain}` +
33
+ `, zeroReward: ${this.zeroReward}` +
34
+ `, frontendTag: "${this.frontendTag}" }`);
35
+ }
36
+ /**
37
+ * Compare to another instance of `StabilityDeposit`.
38
+ */
39
+ equals(that) {
40
+ return (this.initialZUSD.eq(that.initialZUSD) &&
41
+ this.currentZUSD.eq(that.currentZUSD) &&
42
+ this.collateralGain.eq(that.collateralGain) &&
43
+ this.zeroReward.eq(that.zeroReward) &&
44
+ this.frontendTag === that.frontendTag);
45
+ }
46
+ /**
47
+ * Calculate the difference between the `currentZUSD` in this Stability Deposit and `thatZUSD`.
48
+ *
49
+ * @returns An object representing the change, or `undefined` if the deposited amounts are equal.
50
+ */
51
+ whatChanged(thatZUSD) {
52
+ thatZUSD = Decimal_1.Decimal.from(thatZUSD);
53
+ if (thatZUSD.lt(this.currentZUSD)) {
54
+ return { withdrawZUSD: this.currentZUSD.sub(thatZUSD), withdrawAllZUSD: thatZUSD.isZero };
55
+ }
56
+ if (thatZUSD.gt(this.currentZUSD)) {
57
+ return { depositZUSD: thatZUSD.sub(this.currentZUSD) };
58
+ }
59
+ }
60
+ /**
61
+ * Apply a {@link StabilityDepositChange} to this Stability Deposit.
62
+ *
63
+ * @returns The new deposited ZUSD amount.
64
+ */
65
+ apply(change) {
66
+ if (!change) {
67
+ return this.currentZUSD;
68
+ }
69
+ if (change.withdrawZUSD !== undefined) {
70
+ return change.withdrawAllZUSD || this.currentZUSD.lte(change.withdrawZUSD)
71
+ ? Decimal_1.Decimal.ZERO
72
+ : this.currentZUSD.sub(change.withdrawZUSD);
73
+ }
74
+ else {
75
+ return this.currentZUSD.add(change.depositZUSD);
76
+ }
77
+ }
78
+ }
79
+ exports.StabilityDeposit = StabilityDeposit;
80
80
  //# sourceMappingURL=StabilityDeposit.js.map