@agoric/inter-protocol 0.16.1-dev-13050c2.0 → 0.16.1-dev-39b1586.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 +1 -1
- package/bundles/bundle-auctioneer-js-meta.json +181 -181
- package/bundles/bundle-auctioneer.js +1 -1
- package/bundles/bundle-econCommitteeCharter-js-meta.json +129 -129
- package/bundles/bundle-econCommitteeCharter.js +1 -1
- package/bundles/bundle-feeDistributor-js-meta.json +113 -113
- package/bundles/bundle-fluxAggregatorKit-js-meta.json +167 -167
- package/bundles/bundle-fluxAggregatorKit.js +1 -1
- package/bundles/bundle-psm-js-meta.json +168 -168
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-reserve-js-meta.json +164 -164
- package/bundles/bundle-reserve.js +1 -1
- package/bundles/bundle-scaledPriceAuthority-js-meta.json +134 -134
- package/bundles/bundle-vaultFactory-js-meta.json +196 -196
- package/bundles/bundle-vaultFactory.js +1 -1
- package/package.json +19 -19
- package/scripts/add-collateral-core.js +2 -2
- package/src/interest-math.js +13 -13
- package/src/interest.js +24 -24
- package/src/proposals/addAssetToVault.js +5 -5
- package/src/vaultFactory/params.js +4 -4
- package/src/vaultFactory/storeUtils.js +11 -7
- package/src/vaultFactory/types.js +4 -4
- package/src/vaultFactory/vault.js +18 -13
- package/src/vaultFactory/vaultManager.js +32 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/inter-protocol",
|
|
3
|
-
"version": "0.16.1-dev-
|
|
3
|
+
"version": "0.16.1-dev-39b1586.0+39b1586",
|
|
4
4
|
"description": "Core cryptoeconomy contracts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -30,34 +30,34 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@agoric/assert": "0.6.1-dev-
|
|
34
|
-
"@agoric/ertp": "0.16.3-dev-
|
|
35
|
-
"@agoric/governance": "0.10.3-dev-
|
|
36
|
-
"@agoric/internal": "0.3.3-dev-
|
|
37
|
-
"@agoric/notifier": "0.6.3-dev-
|
|
38
|
-
"@agoric/store": "0.9.3-dev-
|
|
39
|
-
"@agoric/time": "0.3.3-dev-
|
|
40
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
41
|
-
"@agoric/vats": "0.15.1-dev-
|
|
42
|
-
"@agoric/zoe": "0.26.3-dev-
|
|
33
|
+
"@agoric/assert": "0.6.1-dev-39b1586.0+39b1586",
|
|
34
|
+
"@agoric/ertp": "0.16.3-dev-39b1586.0+39b1586",
|
|
35
|
+
"@agoric/governance": "0.10.3-dev-39b1586.0+39b1586",
|
|
36
|
+
"@agoric/internal": "0.3.3-dev-39b1586.0+39b1586",
|
|
37
|
+
"@agoric/notifier": "0.6.3-dev-39b1586.0+39b1586",
|
|
38
|
+
"@agoric/store": "0.9.3-dev-39b1586.0+39b1586",
|
|
39
|
+
"@agoric/time": "0.3.3-dev-39b1586.0+39b1586",
|
|
40
|
+
"@agoric/vat-data": "0.5.3-dev-39b1586.0+39b1586",
|
|
41
|
+
"@agoric/vats": "0.15.1-dev-39b1586.0+39b1586",
|
|
42
|
+
"@agoric/zoe": "0.26.3-dev-39b1586.0+39b1586",
|
|
43
43
|
"@endo/captp": "^3.1.1",
|
|
44
44
|
"@endo/eventual-send": "^0.17.2",
|
|
45
45
|
"@endo/far": "^0.2.18",
|
|
46
46
|
"@endo/marshal": "^0.8.5",
|
|
47
47
|
"@endo/nat": "^4.1.27",
|
|
48
|
-
"agoric": "0.21.1-dev-
|
|
48
|
+
"agoric": "0.21.1-dev-39b1586.0+39b1586",
|
|
49
49
|
"jessie.js": "^0.3.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@agoric/deploy-script-support": "0.10.3-dev-
|
|
53
|
-
"@agoric/smart-wallet": "0.5.3-dev-
|
|
54
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
55
|
-
"@agoric/swingset-vat": "0.32.3-dev-
|
|
52
|
+
"@agoric/deploy-script-support": "0.10.3-dev-39b1586.0+39b1586",
|
|
53
|
+
"@agoric/smart-wallet": "0.5.3-dev-39b1586.0+39b1586",
|
|
54
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-39b1586.0+39b1586",
|
|
55
|
+
"@agoric/swingset-vat": "0.32.3-dev-39b1586.0+39b1586",
|
|
56
56
|
"@endo/bundle-source": "^2.5.1",
|
|
57
57
|
"@endo/init": "^0.5.56",
|
|
58
58
|
"@endo/promise-kit": "^0.2.56",
|
|
59
|
-
"@fast-check/ava": "^1.1.
|
|
60
|
-
"ava": "^5.
|
|
59
|
+
"@fast-check/ava": "^1.1.5",
|
|
60
|
+
"ava": "^5.3.0",
|
|
61
61
|
"c8": "^7.13.0",
|
|
62
62
|
"deep-object-diff": "^1.1.9",
|
|
63
63
|
"import-meta-resolve": "^2.2.1"
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"publishConfig": {
|
|
81
81
|
"access": "public"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "39b15861be74ddab196be88f24476f04cc4acb6f"
|
|
84
84
|
}
|
|
@@ -10,7 +10,7 @@ export const defaultProposalBuilder = async (
|
|
|
10
10
|
{ publishRef, install: install0, wrapInstall },
|
|
11
11
|
{
|
|
12
12
|
debtLimitValue = undefined,
|
|
13
|
-
|
|
13
|
+
stabilityFeeValue = undefined,
|
|
14
14
|
interchainAssetOptions = /** @type {object} */ ({}),
|
|
15
15
|
} = {},
|
|
16
16
|
{ env = process.env } = {},
|
|
@@ -38,7 +38,7 @@ export const defaultProposalBuilder = async (
|
|
|
38
38
|
getManifestForAddAssetToVault.name,
|
|
39
39
|
{
|
|
40
40
|
debtLimitValue: debtLimitValue && BigInt(debtLimitValue),
|
|
41
|
-
|
|
41
|
+
stabilityFeeValue: stabilityFeeValue && BigInt(stabilityFeeValue),
|
|
42
42
|
interchainAssetOptions: {
|
|
43
43
|
denom,
|
|
44
44
|
issuerBoardId,
|
package/src/interest-math.js
CHANGED
|
@@ -9,39 +9,39 @@ import {
|
|
|
9
9
|
} from '@agoric/zoe/src/contractSupport/ratio.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @param {Ratio}
|
|
13
|
-
* @param {Ratio}
|
|
12
|
+
* @param {Ratio} currentCompoundedStabilityFee as coefficient
|
|
13
|
+
* @param {Ratio} previousCompoundedStabilityFee as coefficient
|
|
14
14
|
* @returns {Ratio} additional compounding since the previous
|
|
15
15
|
*/
|
|
16
16
|
const calculateRelativeCompounding = (
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
currentCompoundedStabilityFee,
|
|
18
|
+
previousCompoundedStabilityFee,
|
|
19
19
|
) => {
|
|
20
20
|
// divide compounded interest by the snapshot
|
|
21
21
|
return multiplyRatios(
|
|
22
|
-
|
|
23
|
-
invertRatio(
|
|
22
|
+
currentCompoundedStabilityFee,
|
|
23
|
+
invertRatio(previousCompoundedStabilityFee),
|
|
24
24
|
);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @param {Amount<'nat'>} debtSnapshot
|
|
29
|
-
* @param {Ratio}
|
|
30
|
-
* @param {Ratio}
|
|
29
|
+
* @param {Ratio} stabilityFeeSnapshot as coefficient
|
|
30
|
+
* @param {Ratio} currentCompoundedStabilityFee as coefficient
|
|
31
31
|
* @returns {Amount<'nat'>}
|
|
32
32
|
*/
|
|
33
33
|
export const calculateCurrentDebt = (
|
|
34
34
|
debtSnapshot,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
stabilityFeeSnapshot,
|
|
36
|
+
currentCompoundedStabilityFee,
|
|
37
37
|
) => {
|
|
38
|
-
if (ratiosSame(
|
|
38
|
+
if (ratiosSame(stabilityFeeSnapshot, currentCompoundedStabilityFee)) {
|
|
39
39
|
return debtSnapshot;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const interestSinceSnapshot = calculateRelativeCompounding(
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
currentCompoundedStabilityFee,
|
|
44
|
+
stabilityFeeSnapshot,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
return multiplyBy(debtSnapshot, interestSinceSnapshot);
|
package/src/interest.js
CHANGED
|
@@ -57,8 +57,8 @@ export const makeInterestCalculator = (
|
|
|
57
57
|
* @type {Calculate}
|
|
58
58
|
*/
|
|
59
59
|
const calculate = (debtStatus, currentTime) => {
|
|
60
|
-
const { newDebt,
|
|
61
|
-
let newRecent =
|
|
60
|
+
const { newDebt, latestStabilityFeeUpdate } = debtStatus;
|
|
61
|
+
let newRecent = latestStabilityFeeUpdate;
|
|
62
62
|
let growingInterest = debtStatus.interest;
|
|
63
63
|
let growingDebt = newDebt;
|
|
64
64
|
while (
|
|
@@ -78,7 +78,7 @@ export const makeInterestCalculator = (
|
|
|
78
78
|
growingDebt += newInterest;
|
|
79
79
|
}
|
|
80
80
|
return {
|
|
81
|
-
|
|
81
|
+
latestStabilityFeeUpdate: newRecent,
|
|
82
82
|
interest: growingInterest,
|
|
83
83
|
newDebt: growingDebt,
|
|
84
84
|
};
|
|
@@ -93,9 +93,9 @@ export const makeInterestCalculator = (
|
|
|
93
93
|
* @type {Calculate}
|
|
94
94
|
*/
|
|
95
95
|
const calculateReportingPeriod = (debtStatus, currentTime) => {
|
|
96
|
-
const {
|
|
96
|
+
const { latestStabilityFeeUpdate } = debtStatus;
|
|
97
97
|
const overshoot = TimeMath.modRelRel(
|
|
98
|
-
TimeMath.subtractAbsAbs(currentTime,
|
|
98
|
+
TimeMath.subtractAbsAbs(currentTime, latestStabilityFeeUpdate),
|
|
99
99
|
recordingPeriod,
|
|
100
100
|
);
|
|
101
101
|
return calculate(
|
|
@@ -111,20 +111,20 @@ export const makeInterestCalculator = (
|
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* compoundedStabilityFee *= (new debt) / (prior total debt)
|
|
115
115
|
*
|
|
116
|
-
* @param {Ratio}
|
|
116
|
+
* @param {Ratio} priorCompoundedStabilityFee
|
|
117
117
|
* @param {NatValue} priorDebt
|
|
118
118
|
* @param {NatValue} newDebt
|
|
119
119
|
*/
|
|
120
|
-
export const
|
|
121
|
-
|
|
120
|
+
export const calculateCompoundedStabilityFee = (
|
|
121
|
+
priorCompoundedStabilityFee,
|
|
122
122
|
priorDebt,
|
|
123
123
|
newDebt,
|
|
124
124
|
) => {
|
|
125
|
-
const brand =
|
|
125
|
+
const brand = priorCompoundedStabilityFee.numerator.brand;
|
|
126
126
|
const compounded = multiplyRatios(
|
|
127
|
-
|
|
127
|
+
priorCompoundedStabilityFee,
|
|
128
128
|
makeRatio(newDebt, brand, priorDebt, brand),
|
|
129
129
|
);
|
|
130
130
|
return quantize(compounded, COMPOUNDED_INTEREST_DENOMINATOR);
|
|
@@ -144,7 +144,7 @@ const validatedBrand = (mint, debt) => {
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* Charge interest accrued between `
|
|
147
|
+
* Charge interest accrued between `latestStabilityFeeUpdate` and `accruedUntil`.
|
|
148
148
|
*
|
|
149
149
|
* @param {{
|
|
150
150
|
* mint: ZCFMint<'nat'>,
|
|
@@ -152,21 +152,21 @@ const validatedBrand = (mint, debt) => {
|
|
|
152
152
|
* poolIncrementSeat: ZCFSeat,
|
|
153
153
|
* seatAllocationKeyword: Keyword }} powers
|
|
154
154
|
* @param {{
|
|
155
|
-
*
|
|
155
|
+
* stabilityFee: Ratio,
|
|
156
156
|
* chargingPeriod: RelativeTime,
|
|
157
157
|
* recordingPeriod: RelativeTime}} params
|
|
158
158
|
* @param {{
|
|
159
|
-
*
|
|
160
|
-
*
|
|
159
|
+
* latestStabilityFeeUpdate: Timestamp,
|
|
160
|
+
* compoundedStabilityFee: Ratio,
|
|
161
161
|
* totalDebt: Amount<'nat'>}} prior
|
|
162
162
|
* @param {Timestamp} accruedUntil
|
|
163
|
-
* @returns {{
|
|
163
|
+
* @returns {{compoundedStabilityFee: Ratio, latestStabilityFeeUpdate: Timestamp, totalDebt: Amount<'nat'> }}
|
|
164
164
|
*/
|
|
165
165
|
export const chargeInterest = (powers, params, prior, accruedUntil) => {
|
|
166
166
|
const brand = validatedBrand(powers.mint, prior.totalDebt);
|
|
167
167
|
|
|
168
168
|
const interestCalculator = makeInterestCalculator(
|
|
169
|
-
params.
|
|
169
|
+
params.stabilityFee,
|
|
170
170
|
params.chargingPeriod,
|
|
171
171
|
params.recordingPeriod,
|
|
172
172
|
);
|
|
@@ -174,7 +174,7 @@ export const chargeInterest = (powers, params, prior, accruedUntil) => {
|
|
|
174
174
|
// calculate delta of accrued debt
|
|
175
175
|
const debtStatus = interestCalculator.calculateReportingPeriod(
|
|
176
176
|
{
|
|
177
|
-
|
|
177
|
+
latestStabilityFeeUpdate: prior.latestStabilityFeeUpdate,
|
|
178
178
|
newDebt: prior.totalDebt.value,
|
|
179
179
|
interest: 0n, // XXX this is always zero, doesn't need to be an option
|
|
180
180
|
},
|
|
@@ -185,8 +185,8 @@ export const chargeInterest = (powers, params, prior, accruedUntil) => {
|
|
|
185
185
|
// done if none
|
|
186
186
|
if (interestAccrued === 0n) {
|
|
187
187
|
return {
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
compoundedStabilityFee: prior.compoundedStabilityFee,
|
|
189
|
+
latestStabilityFeeUpdate: debtStatus.latestStabilityFeeUpdate,
|
|
190
190
|
totalDebt: prior.totalDebt,
|
|
191
191
|
};
|
|
192
192
|
}
|
|
@@ -196,8 +196,8 @@ export const chargeInterest = (powers, params, prior, accruedUntil) => {
|
|
|
196
196
|
// testing with small numbers there's 5 digits of precision, and with large
|
|
197
197
|
// numbers the ratios tend towards ample precision.
|
|
198
198
|
// TODO adopt banker's rounding https://github.com/Agoric/agoric-sdk/issues/4573
|
|
199
|
-
const
|
|
200
|
-
prior.
|
|
199
|
+
const compoundedStabilityFee = calculateCompoundedStabilityFee(
|
|
200
|
+
prior.compoundedStabilityFee,
|
|
201
201
|
prior.totalDebt.value,
|
|
202
202
|
debtStatus.newDebt,
|
|
203
203
|
);
|
|
@@ -218,8 +218,8 @@ export const chargeInterest = (powers, params, prior, accruedUntil) => {
|
|
|
218
218
|
);
|
|
219
219
|
|
|
220
220
|
return {
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
compoundedStabilityFee,
|
|
222
|
+
latestStabilityFeeUpdate: debtStatus.latestStabilityFeeUpdate,
|
|
223
223
|
totalDebt,
|
|
224
224
|
};
|
|
225
225
|
};
|
|
@@ -212,7 +212,7 @@ export const registerScaledPriceAuthority = async (
|
|
|
212
212
|
* @param {object} config.options
|
|
213
213
|
* @param {InterchainAssetOptions} config.options.interchainAssetOptions
|
|
214
214
|
* @param {bigint | number | string} config.options.debtLimitValue
|
|
215
|
-
* @param {bigint} config.options.
|
|
215
|
+
* @param {bigint} config.options.stabilityFeeValue
|
|
216
216
|
*/
|
|
217
217
|
export const addAssetToVault = async (
|
|
218
218
|
{
|
|
@@ -228,7 +228,7 @@ export const addAssetToVault = async (
|
|
|
228
228
|
debtLimitValue = 1_000n * 1_000_000n,
|
|
229
229
|
// Default to a safe value. Production will likely set this through governance.
|
|
230
230
|
// Allow setting through bootstrap to simplify testing.
|
|
231
|
-
|
|
231
|
+
stabilityFeeValue = 1n,
|
|
232
232
|
interchainAssetOptions,
|
|
233
233
|
},
|
|
234
234
|
},
|
|
@@ -250,7 +250,7 @@ export const addAssetToVault = async (
|
|
|
250
250
|
const vaultFactoryCreator = E.get(vaultFactoryKit).creatorFacet;
|
|
251
251
|
await E(vaultFactoryCreator).addVaultType(interchainIssuer, oracleBrand, {
|
|
252
252
|
debtLimit: AmountMath.make(stable, BigInt(debtLimitValue)),
|
|
253
|
-
|
|
253
|
+
stabilityFee: makeRatio(stabilityFeeValue, stable),
|
|
254
254
|
// The rest of these we use safe defaults.
|
|
255
255
|
// In production they will be governed by the Econ Committee.
|
|
256
256
|
// Product deployments are also expected to have a low debtLimitValue at the outset,
|
|
@@ -268,7 +268,7 @@ export const getManifestForAddAssetToVault = (
|
|
|
268
268
|
{ restoreRef },
|
|
269
269
|
{
|
|
270
270
|
debtLimitValue,
|
|
271
|
-
|
|
271
|
+
stabilityFeeValue,
|
|
272
272
|
interchainAssetOptions,
|
|
273
273
|
scaledPriceAuthorityRef,
|
|
274
274
|
},
|
|
@@ -341,7 +341,7 @@ export const getManifestForAddAssetToVault = (
|
|
|
341
341
|
options: {
|
|
342
342
|
debtLimitValue,
|
|
343
343
|
interchainAssetOptions,
|
|
344
|
-
|
|
344
|
+
stabilityFeeValue,
|
|
345
345
|
},
|
|
346
346
|
};
|
|
347
347
|
};
|
|
@@ -21,7 +21,7 @@ export const DEBT_LIMIT_KEY = 'DebtLimit';
|
|
|
21
21
|
export const LIQUIDATION_MARGIN_KEY = 'LiquidationMargin';
|
|
22
22
|
export const LIQUIDATION_PADDING_KEY = 'LiquidationPadding';
|
|
23
23
|
export const LIQUIDATION_PENALTY_KEY = 'LiquidationPenalty';
|
|
24
|
-
export const
|
|
24
|
+
export const STABILITY_FEE_KEY = 'StabilityFee';
|
|
25
25
|
export const MINT_FEE_KEY = 'MintFee';
|
|
26
26
|
export const MIN_INITIAL_DEBT_KEY = 'MinInitialDebt';
|
|
27
27
|
export const SHORTFALL_INVITATION_KEY = 'ShortfallInvitation';
|
|
@@ -89,7 +89,7 @@ export const makeVaultParamManager = (
|
|
|
89
89
|
publisherKit,
|
|
90
90
|
{
|
|
91
91
|
debtLimit,
|
|
92
|
-
|
|
92
|
+
stabilityFee,
|
|
93
93
|
liquidationMargin,
|
|
94
94
|
liquidationPadding = zeroRatio(liquidationMargin),
|
|
95
95
|
liquidationPenalty,
|
|
@@ -98,7 +98,7 @@ export const makeVaultParamManager = (
|
|
|
98
98
|
) =>
|
|
99
99
|
makeParamManagerSync(publisherKit, {
|
|
100
100
|
[DEBT_LIMIT_KEY]: [ParamTypes.AMOUNT, debtLimit],
|
|
101
|
-
[
|
|
101
|
+
[STABILITY_FEE_KEY]: [ParamTypes.RATIO, stabilityFee],
|
|
102
102
|
[LIQUIDATION_PADDING_KEY]: [ParamTypes.RATIO, liquidationPadding],
|
|
103
103
|
[LIQUIDATION_MARGIN_KEY]: [ParamTypes.RATIO, liquidationMargin],
|
|
104
104
|
[LIQUIDATION_PENALTY_KEY]: [ParamTypes.RATIO, liquidationPenalty],
|
|
@@ -110,7 +110,7 @@ export const vaultParamPattern = M.splitRecord(
|
|
|
110
110
|
{
|
|
111
111
|
liquidationMargin: ratioPattern,
|
|
112
112
|
liquidationPenalty: ratioPattern,
|
|
113
|
-
|
|
113
|
+
stabilityFee: ratioPattern,
|
|
114
114
|
mintFee: ratioPattern,
|
|
115
115
|
debtLimit: amountPattern,
|
|
116
116
|
},
|
|
@@ -131,15 +131,15 @@ harden(fromVaultKey);
|
|
|
131
131
|
* For use by `normalizedCollRatioKey` and tests.
|
|
132
132
|
*
|
|
133
133
|
* @param {PriceQuote} quote
|
|
134
|
-
* @param {Ratio}
|
|
134
|
+
* @param {Ratio} compoundedStabilityFee
|
|
135
135
|
* @param {Ratio} margin
|
|
136
136
|
* @returns {number}
|
|
137
137
|
*/
|
|
138
|
-
export const normalizedCollRatio = (quote,
|
|
138
|
+
export const normalizedCollRatio = (quote, compoundedStabilityFee, margin) => {
|
|
139
139
|
const amountIn = getAmountIn(quote).value;
|
|
140
140
|
const amountOut = getAmountOut(quote).value;
|
|
141
|
-
const interestNumerator =
|
|
142
|
-
const interestBase =
|
|
141
|
+
const interestNumerator = compoundedStabilityFee.numerator.value;
|
|
142
|
+
const interestBase = compoundedStabilityFee.denominator.value;
|
|
143
143
|
const numerator = multiply(
|
|
144
144
|
margin.numerator.value,
|
|
145
145
|
multiply(amountIn, interestNumerator),
|
|
@@ -159,13 +159,17 @@ harden(normalizedCollRatio);
|
|
|
159
159
|
* out the numerator and the denominator, and divide only once.
|
|
160
160
|
*
|
|
161
161
|
* @param {PriceQuote} quote
|
|
162
|
-
* @param {Ratio}
|
|
162
|
+
* @param {Ratio} compoundedStabilityFee
|
|
163
163
|
* @param {Ratio} margin
|
|
164
164
|
* @returns {string} lexically sortable string in which highest
|
|
165
165
|
* debt-to-collateral is earliest
|
|
166
166
|
*/
|
|
167
|
-
export const normalizedCollRatioKey = (
|
|
168
|
-
|
|
167
|
+
export const normalizedCollRatioKey = (
|
|
168
|
+
quote,
|
|
169
|
+
compoundedStabilityFee,
|
|
170
|
+
margin,
|
|
171
|
+
) => {
|
|
172
|
+
const collRatio = normalizedCollRatio(quote, compoundedStabilityFee, margin);
|
|
169
173
|
return `${encodeNumber(collRatio)}:`;
|
|
170
174
|
};
|
|
171
175
|
harden(normalizedCollRatioKey);
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @property {Ratio} liquidationMargin - margin below which collateral will be
|
|
27
27
|
* liquidated to satisfy the debt.
|
|
28
28
|
* @property {Ratio} liquidationPenalty - penalty charged upon liquidation as proportion of debt
|
|
29
|
-
* @property {Ratio}
|
|
29
|
+
* @property {Ratio} stabilityFee - annual interest rate charged on debt positions
|
|
30
30
|
* @property {Ratio} mintFee - The fee (in BasisPoints) charged when creating
|
|
31
31
|
* or increasing a debt position.
|
|
32
32
|
* @property {Amount<'nat'>} debtLimit
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
* @property {() => Ratio} getLiquidationMargin
|
|
79
79
|
* @property {() => Ratio} getMintFee
|
|
80
80
|
* @property {() => Promise<PriceQuote>} getCollateralQuote
|
|
81
|
-
* @property {() => Ratio}
|
|
81
|
+
* @property {() => Ratio} getStabilityFee - The annual interest rate on a debt position
|
|
82
82
|
* @property {() => RelativeTime} getChargingPeriod - The period (in seconds) at
|
|
83
83
|
* which interest is charged to the debt position.
|
|
84
84
|
* @property {() => RelativeTime} getRecordingPeriod - The period (in seconds)
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* @typedef {object} DebtStatus
|
|
112
|
-
* @property {Timestamp}
|
|
113
|
-
* @property {NatValue} interest interest accrued since
|
|
112
|
+
* @property {Timestamp} latestStabilityFeeUpdate
|
|
113
|
+
* @property {NatValue} interest interest accrued since latestStabilityFeeUpdate
|
|
114
114
|
* @property {NatValue} newDebt total including principal and interest
|
|
115
115
|
*/
|
|
116
116
|
|
|
@@ -72,7 +72,7 @@ const validTransitions = {
|
|
|
72
72
|
*
|
|
73
73
|
* @typedef {object} VaultNotification
|
|
74
74
|
* @property {Amount<'nat'>} locked Amount of Collateral locked
|
|
75
|
-
* @property {{debt: Amount<'nat'>,
|
|
75
|
+
* @property {{debt: Amount<'nat'>, stabilityFee: Ratio}} debtSnapshot 'debt' at the point the compounded stabilityFee was 'stabilityFee'
|
|
76
76
|
* @property {HolderPhase} vaultState
|
|
77
77
|
*/
|
|
78
78
|
|
|
@@ -86,7 +86,7 @@ const validTransitions = {
|
|
|
86
86
|
* @property {() => Brand<'nat'>} getDebtBrand
|
|
87
87
|
* @property {MintAndTransfer} mintAndTransfer
|
|
88
88
|
* @property {(amount: Amount, seat: ZCFSeat) => void} burn
|
|
89
|
-
* @property {() => Ratio}
|
|
89
|
+
* @property {() => Ratio} getCompoundedStabilityFee
|
|
90
90
|
* @property {(oldDebt: import('./storeUtils.js').NormalizedDebt, oldCollateral: Amount<'nat'>, vaultId: VaultId, vaultPhase: VaultPhase, vault: Vault) => void} handleBalanceChange
|
|
91
91
|
* @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams
|
|
92
92
|
*/
|
|
@@ -104,7 +104,7 @@ const validTransitions = {
|
|
|
104
104
|
* Snapshot is of the debt and compounded interest when the principal was last changed.
|
|
105
105
|
*
|
|
106
106
|
* @typedef {{
|
|
107
|
-
*
|
|
107
|
+
* stabilityFeeSnapshot: Ratio,
|
|
108
108
|
* phase: VaultPhase,
|
|
109
109
|
* debtSnapshot: Amount<'nat'>,
|
|
110
110
|
* outerUpdater: import('@agoric/zoe/src/contractSupport/recorder.js').Recorder<VaultNotification> | null,
|
|
@@ -132,7 +132,7 @@ const VaultStateShape = harden({
|
|
|
132
132
|
phase: M.any(),
|
|
133
133
|
storageNode: M.any(),
|
|
134
134
|
vaultSeat: M.any(),
|
|
135
|
-
|
|
135
|
+
stabilityFeeSnapshot: M.any(),
|
|
136
136
|
debtSnapshot: M.any(),
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -174,7 +174,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
174
174
|
vaultSeat: zcf.makeEmptySeatKit().zcfSeat,
|
|
175
175
|
|
|
176
176
|
// Two values from the same moment
|
|
177
|
-
|
|
177
|
+
stabilityFeeSnapshot: manager.getCompoundedStabilityFee(),
|
|
178
178
|
debtSnapshot: AmountMath.makeEmpty(manager.getDebtBrand()),
|
|
179
179
|
});
|
|
180
180
|
},
|
|
@@ -257,7 +257,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
257
257
|
|
|
258
258
|
// update local state
|
|
259
259
|
state.debtSnapshot = newDebt;
|
|
260
|
-
state.
|
|
260
|
+
state.stabilityFeeSnapshot =
|
|
261
|
+
state.manager.getCompoundedStabilityFee();
|
|
261
262
|
},
|
|
262
263
|
|
|
263
264
|
/**
|
|
@@ -327,10 +328,11 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
327
328
|
getStateSnapshot(newPhase) {
|
|
328
329
|
const { state, facets } = this;
|
|
329
330
|
|
|
330
|
-
const { debtSnapshot: debt,
|
|
331
|
+
const { debtSnapshot: debt, stabilityFeeSnapshot: stabilityFee } =
|
|
332
|
+
state;
|
|
331
333
|
/** @type {VaultNotification} */
|
|
332
334
|
return harden({
|
|
333
|
-
debtSnapshot: { debt,
|
|
335
|
+
debtSnapshot: { debt, stabilityFee },
|
|
334
336
|
locked: facets.self.getCollateralAmount(),
|
|
335
337
|
// newPhase param is so that makeTransferInvitation can finish without setting the vault's phase
|
|
336
338
|
// TODO refactor https://github.com/Agoric/agoric-sdk/issues/4415
|
|
@@ -785,7 +787,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
785
787
|
helper.updateDebtSnapshot(self.getCurrentDebt());
|
|
786
788
|
const {
|
|
787
789
|
debtSnapshot: debt,
|
|
788
|
-
|
|
790
|
+
stabilityFeeSnapshot: stabilityFee,
|
|
789
791
|
phase,
|
|
790
792
|
} = state;
|
|
791
793
|
if (outerUpdater) {
|
|
@@ -795,7 +797,7 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
795
797
|
state.outerUpdater = null;
|
|
796
798
|
}
|
|
797
799
|
const transferState = {
|
|
798
|
-
debtSnapshot: { debt,
|
|
800
|
+
debtSnapshot: { debt, stabilityFee },
|
|
799
801
|
locked: self.getCollateralAmount(),
|
|
800
802
|
vaultState: phase,
|
|
801
803
|
};
|
|
@@ -839,8 +841,8 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
839
841
|
const { state } = this;
|
|
840
842
|
return calculateCurrentDebt(
|
|
841
843
|
state.debtSnapshot,
|
|
842
|
-
state.
|
|
843
|
-
state.manager.
|
|
844
|
+
state.stabilityFeeSnapshot,
|
|
845
|
+
state.manager.getCompoundedStabilityFee(),
|
|
844
846
|
);
|
|
845
847
|
},
|
|
846
848
|
|
|
@@ -857,7 +859,10 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
|
|
|
857
859
|
getNormalizedDebt() {
|
|
858
860
|
const { state } = this;
|
|
859
861
|
// @ts-expect-error cast
|
|
860
|
-
return reverseInterest(
|
|
862
|
+
return reverseInterest(
|
|
863
|
+
state.debtSnapshot,
|
|
864
|
+
state.stabilityFeeSnapshot,
|
|
865
|
+
);
|
|
861
866
|
},
|
|
862
867
|
},
|
|
863
868
|
},
|