@agoric/inter-protocol 0.16.1-dev-69236fd.0 → 0.16.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.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/bundles/bundle-auctioneer-js-meta.json +285 -285
- package/bundles/bundle-auctioneer.js +1 -1
- package/bundles/bundle-econCommitteeCharter-js-meta.json +201 -201
- package/bundles/bundle-econCommitteeCharter.js +1 -1
- package/bundles/bundle-feeDistributor-js-meta.json +201 -201
- package/bundles/bundle-feeDistributor.js +1 -1
- package/bundles/bundle-fluxAggregatorKit-js-meta.json +307 -307
- package/bundles/bundle-fluxAggregatorKit.js +1 -1
- package/bundles/bundle-psm-js-meta.json +264 -264
- package/bundles/bundle-psm.js +1 -1
- package/bundles/bundle-reserve-js-meta.json +295 -295
- package/bundles/bundle-reserve.js +1 -1
- package/bundles/bundle-scaledPriceAuthority-js-meta.json +225 -225
- package/bundles/bundle-scaledPriceAuthority.js +1 -1
- package/bundles/bundle-vaultFactory-js-meta.json +346 -346
- package/bundles/bundle-vaultFactory.js +1 -1
- package/package.json +17 -18
- package/scripts/add-collateral-core.js +2 -2
- package/src/auction/scheduler.js +12 -2
- package/src/interest-math.js +13 -13
- package/src/interest.js +24 -24
- package/src/price/fluxAggregatorContract.js +8 -4
- package/src/proposals/addAssetToVault.js +7 -19
- package/src/proposals/price-feed-proposal.js +15 -29
- package/src/proposals/startPSM.js +4 -6
- package/src/reserve/assetReserve.js +2 -2
- package/src/vaultFactory/params.js +4 -4
- package/src/vaultFactory/storeUtils.js +7 -11
- package/src/vaultFactory/types.js +4 -4
- package/src/vaultFactory/vault.js +13 -18
- package/src/vaultFactory/vaultDirector.js +0 -2
- package/src/vaultFactory/vaultManager.js +40 -47
- package/scripts/add-STARS.js +0 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/inter-protocol",
|
|
3
|
-
"version": "0.16.1
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Core cryptoeconomy contracts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "yarn build:bundles",
|
|
12
12
|
"build:bundles": "node ./scripts/build-bundles.js",
|
|
13
|
-
"build:add-STARS-proposal": "agoric run scripts/add-STARS.js",
|
|
14
13
|
"test": "ava",
|
|
15
14
|
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
|
|
16
15
|
"test:xs": "exit 0",
|
|
@@ -30,29 +29,29 @@
|
|
|
30
29
|
},
|
|
31
30
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
32
31
|
"dependencies": {
|
|
33
|
-
"@agoric/assert": "0.6.
|
|
34
|
-
"@agoric/ertp": "0.16.
|
|
35
|
-
"@agoric/governance": "0.10.3
|
|
36
|
-
"@agoric/internal": "0.3.
|
|
37
|
-
"@agoric/notifier": "0.6.
|
|
38
|
-
"@agoric/store": "0.9.
|
|
39
|
-
"@agoric/time": "0.3.
|
|
40
|
-
"@agoric/vat-data": "0.5.
|
|
41
|
-
"@agoric/vats": "0.15.1
|
|
42
|
-
"@agoric/zoe": "0.26.
|
|
32
|
+
"@agoric/assert": "^0.6.0",
|
|
33
|
+
"@agoric/ertp": "^0.16.2",
|
|
34
|
+
"@agoric/governance": "^0.10.3",
|
|
35
|
+
"@agoric/internal": "^0.3.2",
|
|
36
|
+
"@agoric/notifier": "^0.6.2",
|
|
37
|
+
"@agoric/store": "^0.9.2",
|
|
38
|
+
"@agoric/time": "^0.3.2",
|
|
39
|
+
"@agoric/vat-data": "^0.5.2",
|
|
40
|
+
"@agoric/vats": "^0.15.1",
|
|
41
|
+
"@agoric/zoe": "^0.26.2",
|
|
43
42
|
"@endo/captp": "^3.1.1",
|
|
44
43
|
"@endo/eventual-send": "^0.17.2",
|
|
45
44
|
"@endo/far": "^0.2.18",
|
|
46
45
|
"@endo/marshal": "^0.8.5",
|
|
47
46
|
"@endo/nat": "^4.1.27",
|
|
48
|
-
"agoric": "0.21.1
|
|
47
|
+
"agoric": "^0.21.1",
|
|
49
48
|
"jessie.js": "^0.3.2"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@agoric/deploy-script-support": "0.10.3
|
|
53
|
-
"@agoric/smart-wallet": "0.5.3
|
|
54
|
-
"@agoric/swingset-liveslots": "0.10.
|
|
55
|
-
"@agoric/swingset-vat": "0.32.
|
|
51
|
+
"@agoric/deploy-script-support": "^0.10.3",
|
|
52
|
+
"@agoric/smart-wallet": "^0.5.3",
|
|
53
|
+
"@agoric/swingset-liveslots": "^0.10.2",
|
|
54
|
+
"@agoric/swingset-vat": "^0.32.2",
|
|
56
55
|
"@endo/bundle-source": "^2.5.1",
|
|
57
56
|
"@endo/init": "^0.5.56",
|
|
58
57
|
"@endo/promise-kit": "^0.2.56",
|
|
@@ -80,5 +79,5 @@
|
|
|
80
79
|
"publishConfig": {
|
|
81
80
|
"access": "public"
|
|
82
81
|
},
|
|
83
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "ba3b776444425bbcb275ce918794d9259f8e15da"
|
|
84
83
|
}
|
|
@@ -10,7 +10,7 @@ export const defaultProposalBuilder = async (
|
|
|
10
10
|
{ publishRef, install: install0, wrapInstall },
|
|
11
11
|
{
|
|
12
12
|
debtLimitValue = undefined,
|
|
13
|
-
|
|
13
|
+
interestRateValue = 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
|
+
interestRateValue: interestRateValue && BigInt(interestRateValue),
|
|
42
42
|
interchainAssetOptions: {
|
|
43
43
|
denom,
|
|
44
44
|
issuerBoardId,
|
package/src/auction/scheduler.js
CHANGED
|
@@ -149,7 +149,18 @@ export const makeScheduler = async (
|
|
|
149
149
|
auctionState = AuctionState.WAITING;
|
|
150
150
|
auctionDriver.finalize();
|
|
151
151
|
|
|
152
|
-
if (
|
|
152
|
+
if (nextSchedule) {
|
|
153
|
+
// only recalculate the next schedule at this point if the lock time has
|
|
154
|
+
// not been reached.
|
|
155
|
+
const nextLock = nextSchedule.lockTime;
|
|
156
|
+
if (nextLock && TimeMath.compareAbs(now, nextLock) < 0) {
|
|
157
|
+
const afterNow = TimeMath.addAbsRel(
|
|
158
|
+
now,
|
|
159
|
+
TimeMath.coerceRelativeTimeRecord(1n, timerBrand),
|
|
160
|
+
);
|
|
161
|
+
nextSchedule = safelyComputeRoundTiming(params, afterNow);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
153
164
|
console.error(
|
|
154
165
|
'🛠️ finishAuctionRound without scheduling the next; repair with new auctioneer params',
|
|
155
166
|
);
|
|
@@ -322,7 +333,6 @@ export const makeScheduler = async (
|
|
|
322
333
|
// NB: may be fired with the initial params as well
|
|
323
334
|
async updateState(_newState) {
|
|
324
335
|
trace('received param update', _newState);
|
|
325
|
-
await null;
|
|
326
336
|
if (!nextSchedule) {
|
|
327
337
|
trace('repairing nextSchedule and restarting');
|
|
328
338
|
({ nextSchedule } = await initializeNextSchedule());
|
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} currentCompoundedInterest as coefficient
|
|
13
|
+
* @param {Ratio} previousCompoundedInterest as coefficient
|
|
14
14
|
* @returns {Ratio} additional compounding since the previous
|
|
15
15
|
*/
|
|
16
16
|
const calculateRelativeCompounding = (
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
currentCompoundedInterest,
|
|
18
|
+
previousCompoundedInterest,
|
|
19
19
|
) => {
|
|
20
20
|
// divide compounded interest by the snapshot
|
|
21
21
|
return multiplyRatios(
|
|
22
|
-
|
|
23
|
-
invertRatio(
|
|
22
|
+
currentCompoundedInterest,
|
|
23
|
+
invertRatio(previousCompoundedInterest),
|
|
24
24
|
);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @param {Amount<'nat'>} debtSnapshot
|
|
29
|
-
* @param {Ratio}
|
|
30
|
-
* @param {Ratio}
|
|
29
|
+
* @param {Ratio} interestSnapshot as coefficient
|
|
30
|
+
* @param {Ratio} currentCompoundedInterest as coefficient
|
|
31
31
|
* @returns {Amount<'nat'>}
|
|
32
32
|
*/
|
|
33
33
|
export const calculateCurrentDebt = (
|
|
34
34
|
debtSnapshot,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
interestSnapshot,
|
|
36
|
+
currentCompoundedInterest,
|
|
37
37
|
) => {
|
|
38
|
-
if (ratiosSame(
|
|
38
|
+
if (ratiosSame(interestSnapshot, currentCompoundedInterest)) {
|
|
39
39
|
return debtSnapshot;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const interestSinceSnapshot = calculateRelativeCompounding(
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
currentCompoundedInterest,
|
|
44
|
+
interestSnapshot,
|
|
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, latestInterestUpdate } = debtStatus;
|
|
61
|
+
let newRecent = latestInterestUpdate;
|
|
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
|
+
latestInterestUpdate: 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 { latestInterestUpdate } = debtStatus;
|
|
97
97
|
const overshoot = TimeMath.modRelRel(
|
|
98
|
-
TimeMath.subtractAbsAbs(currentTime,
|
|
98
|
+
TimeMath.subtractAbsAbs(currentTime, latestInterestUpdate),
|
|
99
99
|
recordingPeriod,
|
|
100
100
|
);
|
|
101
101
|
return calculate(
|
|
@@ -111,20 +111,20 @@ export const makeInterestCalculator = (
|
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* compoundedInterest *= (new debt) / (prior total debt)
|
|
115
115
|
*
|
|
116
|
-
* @param {Ratio}
|
|
116
|
+
* @param {Ratio} priorCompoundedInterest
|
|
117
117
|
* @param {NatValue} priorDebt
|
|
118
118
|
* @param {NatValue} newDebt
|
|
119
119
|
*/
|
|
120
|
-
export const
|
|
121
|
-
|
|
120
|
+
export const calculateCompoundedInterest = (
|
|
121
|
+
priorCompoundedInterest,
|
|
122
122
|
priorDebt,
|
|
123
123
|
newDebt,
|
|
124
124
|
) => {
|
|
125
|
-
const brand =
|
|
125
|
+
const brand = priorCompoundedInterest.numerator.brand;
|
|
126
126
|
const compounded = multiplyRatios(
|
|
127
|
-
|
|
127
|
+
priorCompoundedInterest,
|
|
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 `latestInterestUpdate` 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
|
+
* interestRate: Ratio,
|
|
156
156
|
* chargingPeriod: RelativeTime,
|
|
157
157
|
* recordingPeriod: RelativeTime}} params
|
|
158
158
|
* @param {{
|
|
159
|
-
*
|
|
160
|
-
*
|
|
159
|
+
* latestInterestUpdate: Timestamp,
|
|
160
|
+
* compoundedInterest: Ratio,
|
|
161
161
|
* totalDebt: Amount<'nat'>}} prior
|
|
162
162
|
* @param {Timestamp} accruedUntil
|
|
163
|
-
* @returns {{
|
|
163
|
+
* @returns {{compoundedInterest: Ratio, latestInterestUpdate: 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.interestRate,
|
|
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
|
+
latestInterestUpdate: prior.latestInterestUpdate,
|
|
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
|
+
compoundedInterest: prior.compoundedInterest,
|
|
189
|
+
latestInterestUpdate: debtStatus.latestInterestUpdate,
|
|
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 compoundedInterest = calculateCompoundedInterest(
|
|
200
|
+
prior.compoundedInterest,
|
|
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
|
+
compoundedInterest,
|
|
222
|
+
latestInterestUpdate: debtStatus.latestInterestUpdate,
|
|
223
223
|
totalDebt,
|
|
224
224
|
};
|
|
225
225
|
};
|
|
@@ -131,8 +131,10 @@ export const prepare = async (zcf, privateArgs, baggage) => {
|
|
|
131
131
|
addr,
|
|
132
132
|
[invitation],
|
|
133
133
|
);
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
if (highPrioritySendersManager) {
|
|
135
|
+
// eslint-disable-next-line @jessie.js/no-nested-await -- after another await
|
|
136
|
+
await E(highPrioritySendersManager).add(description, addr);
|
|
137
|
+
}
|
|
136
138
|
return `added ${addr}`;
|
|
137
139
|
};
|
|
138
140
|
|
|
@@ -144,8 +146,10 @@ export const prepare = async (zcf, privateArgs, baggage) => {
|
|
|
144
146
|
const removeOracle = async addr => {
|
|
145
147
|
trace('removeOracle', addr);
|
|
146
148
|
await E(faKit.creator).removeOracle(addr);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
if (highPrioritySendersManager) {
|
|
150
|
+
// eslint-disable-next-line @jessie.js/no-nested-await -- after another await
|
|
151
|
+
await E(highPrioritySendersManager).remove(description, addr);
|
|
152
|
+
}
|
|
149
153
|
return `removed ${addr}`;
|
|
150
154
|
};
|
|
151
155
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// @jessie-check
|
|
2
2
|
|
|
3
3
|
import { AmountMath, AssetKind } from '@agoric/ertp';
|
|
4
|
+
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
|
|
4
5
|
import { deeplyFulfilledObject } from '@agoric/internal';
|
|
5
6
|
import { Stable } from '@agoric/vats/src/tokens.js';
|
|
6
|
-
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
|
|
7
|
-
import { parseRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
|
|
8
7
|
import { E } from '@endo/far';
|
|
9
|
-
import {
|
|
8
|
+
import { parseRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
|
|
10
9
|
import { reserveThenGetNames } from './utils.js';
|
|
11
10
|
|
|
12
11
|
export * from './startPSM.js';
|
|
@@ -212,7 +211,7 @@ export const registerScaledPriceAuthority = async (
|
|
|
212
211
|
* @param {object} config.options
|
|
213
212
|
* @param {InterchainAssetOptions} config.options.interchainAssetOptions
|
|
214
213
|
* @param {bigint | number | string} config.options.debtLimitValue
|
|
215
|
-
* @param {bigint} config.options.
|
|
214
|
+
* @param {bigint} config.options.interestRateValue
|
|
216
215
|
*/
|
|
217
216
|
export const addAssetToVault = async (
|
|
218
217
|
{
|
|
@@ -220,7 +219,6 @@ export const addAssetToVault = async (
|
|
|
220
219
|
brand: {
|
|
221
220
|
consume: { [Stable.symbol]: stableP },
|
|
222
221
|
},
|
|
223
|
-
instance: { consume: consumeInstance },
|
|
224
222
|
},
|
|
225
223
|
{
|
|
226
224
|
options: {
|
|
@@ -228,7 +226,7 @@ export const addAssetToVault = async (
|
|
|
228
226
|
debtLimitValue = 1_000n * 1_000_000n,
|
|
229
227
|
// Default to a safe value. Production will likely set this through governance.
|
|
230
228
|
// Allow setting through bootstrap to simplify testing.
|
|
231
|
-
|
|
229
|
+
interestRateValue = 1n,
|
|
232
230
|
interchainAssetOptions,
|
|
233
231
|
},
|
|
234
232
|
},
|
|
@@ -241,16 +239,11 @@ export const addAssetToVault = async (
|
|
|
241
239
|
[keyword],
|
|
242
240
|
);
|
|
243
241
|
|
|
244
|
-
const oracleInstanceName = instanceNameFor(oracleBrand, 'USD');
|
|
245
|
-
// don't add the collateral offering to vaultFactory until its price feed is available
|
|
246
|
-
// eslint-disable-next-line no-restricted-syntax -- allow this computed property
|
|
247
|
-
await consumeInstance[oracleInstanceName];
|
|
248
|
-
|
|
249
242
|
const stable = await stableP;
|
|
250
243
|
const vaultFactoryCreator = E.get(vaultFactoryKit).creatorFacet;
|
|
251
244
|
await E(vaultFactoryCreator).addVaultType(interchainIssuer, oracleBrand, {
|
|
252
245
|
debtLimit: AmountMath.make(stable, BigInt(debtLimitValue)),
|
|
253
|
-
|
|
246
|
+
interestRate: makeRatio(interestRateValue, stable),
|
|
254
247
|
// The rest of these we use safe defaults.
|
|
255
248
|
// In production they will be governed by the Econ Committee.
|
|
256
249
|
// Product deployments are also expected to have a low debtLimitValue at the outset,
|
|
@@ -268,7 +261,7 @@ export const getManifestForAddAssetToVault = (
|
|
|
268
261
|
{ restoreRef },
|
|
269
262
|
{
|
|
270
263
|
debtLimitValue,
|
|
271
|
-
|
|
264
|
+
interestRateValue,
|
|
272
265
|
interchainAssetOptions,
|
|
273
266
|
scaledPriceAuthorityRef,
|
|
274
267
|
},
|
|
@@ -328,11 +321,6 @@ export const getManifestForAddAssetToVault = (
|
|
|
328
321
|
brand: {
|
|
329
322
|
consume: { [Stable.symbol]: true },
|
|
330
323
|
},
|
|
331
|
-
instance: {
|
|
332
|
-
// allow any instance because the AGORIC_INSTANCE_NAME of
|
|
333
|
-
// priceFeedOptions cannot be known statically.
|
|
334
|
-
consume: true,
|
|
335
|
-
},
|
|
336
324
|
},
|
|
337
325
|
},
|
|
338
326
|
installations: {
|
|
@@ -341,7 +329,7 @@ export const getManifestForAddAssetToVault = (
|
|
|
341
329
|
options: {
|
|
342
330
|
debtLimitValue,
|
|
343
331
|
interchainAssetOptions,
|
|
344
|
-
|
|
332
|
+
interestRateValue,
|
|
345
333
|
},
|
|
346
334
|
};
|
|
347
335
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @ts-nocheck -- lots of type errors. low prio b/c proposals are like scripts
|
|
2
|
-
import {
|
|
2
|
+
import { E } from '@endo/far';
|
|
3
3
|
import {
|
|
4
|
-
assertPathSegment,
|
|
5
4
|
makeStorageNodeChild,
|
|
5
|
+
assertPathSegment,
|
|
6
6
|
} from '@agoric/internal/src/lib-chainStorage.js';
|
|
7
|
-
import {
|
|
7
|
+
import { makeTracer } from '@agoric/internal';
|
|
8
8
|
|
|
9
9
|
import { unitAmount } from '@agoric/zoe/src/contractSupport/priceQuote.js';
|
|
10
10
|
import { reserveThenDeposit, reserveThenGetNames } from './utils.js';
|
|
@@ -18,9 +18,6 @@ const sanitizePathSegment = name => {
|
|
|
18
18
|
return candidate;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export const instanceNameFor = (inBrandName, outBrandName) =>
|
|
22
|
-
`${inBrandName}-${outBrandName} price feed`;
|
|
23
|
-
|
|
24
21
|
/**
|
|
25
22
|
* @typedef {{
|
|
26
23
|
* brandIn?: ERef<Brand<'nat'> | undefined>,
|
|
@@ -65,6 +62,7 @@ export const ensureOracleBrands = async (
|
|
|
65
62
|
let b = await brand;
|
|
66
63
|
if (!b) {
|
|
67
64
|
// not 1st await
|
|
65
|
+
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
68
66
|
b = await E(agoricNames).provideInertBrand(
|
|
69
67
|
name,
|
|
70
68
|
harden({ decimalPlaces: parseInt(decimals, 10) }),
|
|
@@ -98,7 +96,6 @@ export const createPriceFeed = async (
|
|
|
98
96
|
priceAuthorityAdmin,
|
|
99
97
|
startGovernedUpgradable,
|
|
100
98
|
},
|
|
101
|
-
instance: { produce: produceInstance },
|
|
102
99
|
},
|
|
103
100
|
{
|
|
104
101
|
options: {
|
|
@@ -164,27 +161,11 @@ export const createPriceFeed = async (
|
|
|
164
161
|
installation: priceAggregator,
|
|
165
162
|
});
|
|
166
163
|
|
|
167
|
-
|
|
168
|
-
const forceReplace = true;
|
|
169
|
-
// Make sure this PA is registered before sharing the instance in agoricNames,
|
|
170
|
-
// which allows contracts that depend on the registry value to wait for it and
|
|
171
|
-
// prevent a race.
|
|
172
|
-
await E(priceAuthorityAdmin).registerPriceAuthority(
|
|
173
|
-
E(faKit.publicFacet).getPriceAuthority(),
|
|
174
|
-
brandIn,
|
|
175
|
-
brandOut,
|
|
176
|
-
forceReplace,
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
await E(E(agoricNamesAdmin).lookupAdmin('instance'))
|
|
164
|
+
E(E(agoricNamesAdmin).lookupAdmin('instance'))
|
|
180
165
|
.update(AGORIC_INSTANCE_NAME, faKit.instance)
|
|
181
166
|
.catch(err =>
|
|
182
167
|
console.error(`🚨 failed to update ${AGORIC_INSTANCE_NAME}`, err),
|
|
183
168
|
);
|
|
184
|
-
// being after the above awaits means that when this resolves, the consumer
|
|
185
|
-
// gets notified that the authority is in the registry and its instance is in
|
|
186
|
-
// agoricNames.
|
|
187
|
-
produceInstance[AGORIC_INSTANCE_NAME].resolve(faKit.instance);
|
|
188
169
|
|
|
189
170
|
E(E.get(econCharterKit).creatorFacet).addInstance(
|
|
190
171
|
faKit.instance,
|
|
@@ -193,6 +174,15 @@ export const createPriceFeed = async (
|
|
|
193
174
|
);
|
|
194
175
|
trace('registered', AGORIC_INSTANCE_NAME, faKit.instance);
|
|
195
176
|
|
|
177
|
+
// Publish price feed in home.priceAuthority.
|
|
178
|
+
const forceReplace = true;
|
|
179
|
+
void E(priceAuthorityAdmin).registerPriceAuthority(
|
|
180
|
+
E(faKit.publicFacet).getPriceAuthority(),
|
|
181
|
+
brandIn,
|
|
182
|
+
brandOut,
|
|
183
|
+
forceReplace,
|
|
184
|
+
);
|
|
185
|
+
|
|
196
186
|
/**
|
|
197
187
|
* Initialize a new oracle and send an invitation to administer it.
|
|
198
188
|
*
|
|
@@ -242,9 +232,6 @@ export const getManifestForPriceFeed = async (
|
|
|
242
232
|
priceAuthorityAdmin: t,
|
|
243
233
|
startGovernedUpgradable: t,
|
|
244
234
|
},
|
|
245
|
-
instance: {
|
|
246
|
-
produce: t,
|
|
247
|
-
},
|
|
248
235
|
},
|
|
249
236
|
[ensureOracleBrands.name]: {
|
|
250
237
|
namedVat: {
|
|
@@ -256,7 +243,6 @@ export const getManifestForPriceFeed = async (
|
|
|
256
243
|
},
|
|
257
244
|
},
|
|
258
245
|
installations: {
|
|
259
|
-
// ??? will every eval of price-feed-proposal install priceAggregator ?
|
|
260
246
|
priceAggregator: restoreRef(priceFeedOptions.priceAggregatorRef),
|
|
261
247
|
},
|
|
262
248
|
options: {
|
|
@@ -317,7 +303,7 @@ export const startPriceFeeds = async (
|
|
|
317
303
|
{
|
|
318
304
|
options: {
|
|
319
305
|
priceFeedOptions: {
|
|
320
|
-
AGORIC_INSTANCE_NAME:
|
|
306
|
+
AGORIC_INSTANCE_NAME: `${inBrandName}-${outBrandName} price feed`,
|
|
321
307
|
contractTerms: {
|
|
322
308
|
minSubmissionCount: 2,
|
|
323
309
|
minSubmissionValue: 1,
|
|
@@ -363,25 +363,23 @@ export const makeAnchorAsset = async (
|
|
|
363
363
|
slotToBoardRemote,
|
|
364
364
|
);
|
|
365
365
|
const metricsKey = `${stablePsmKey}.${keyword}.metrics`;
|
|
366
|
-
|
|
367
|
-
if (!toSlotReviver.has(metricsKey)) {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
366
|
+
if (toSlotReviver.has(metricsKey)) {
|
|
370
367
|
const metrics = toSlotReviver.getItem(metricsKey);
|
|
371
368
|
produceAnchorBalancePayments.resolve(
|
|
372
369
|
makeScalarBigMapStore('Anchor balance payments', { durable: true }),
|
|
373
370
|
);
|
|
374
371
|
// XXX this rule should only apply to the 1st await
|
|
372
|
+
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
375
373
|
const anchorPaymentMap = await anchorBalancePayments;
|
|
376
374
|
|
|
377
375
|
// TODO: validate that `metrics.anchorPoolBalance.value` is
|
|
378
376
|
// pass-by-copy PureData (e.g., contains no remotables).
|
|
377
|
+
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
379
378
|
const pmt = await E(mint).mintPayment(
|
|
380
379
|
AmountMath.make(brand, metrics.anchorPoolBalance.value),
|
|
381
380
|
);
|
|
382
381
|
anchorPaymentMap.init(brand, pmt);
|
|
383
|
-
}
|
|
384
|
-
await maybeReviveMetrics();
|
|
382
|
+
}
|
|
385
383
|
|
|
386
384
|
await Promise.all([
|
|
387
385
|
E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(keyword, kit.issuer),
|
|
@@ -66,11 +66,11 @@ export const prepare = async (zcf, privateArgs, baggage) => {
|
|
|
66
66
|
};
|
|
67
67
|
trace('awaiting takeFeeMint');
|
|
68
68
|
const feeMint = await takeFeeMint();
|
|
69
|
-
const storageNode = await privateArgs.storageNode;
|
|
70
69
|
const makeAssetReserveKit = await prepareAssetReserveKit(baggage, {
|
|
71
70
|
feeMint,
|
|
72
71
|
makeRecorderKit,
|
|
73
|
-
|
|
72
|
+
// eslint-disable-next-line @jessie.js/no-nested-await -- spurious
|
|
73
|
+
storageNode: await privateArgs.storageNode,
|
|
74
74
|
zcf,
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -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 INTEREST_RATE_KEY = 'InterestRate';
|
|
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
|
+
interestRate,
|
|
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
|
+
[INTEREST_RATE_KEY]: [ParamTypes.RATIO, interestRate],
|
|
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
|
+
interestRate: 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} compoundedInterest
|
|
135
135
|
* @param {Ratio} margin
|
|
136
136
|
* @returns {number}
|
|
137
137
|
*/
|
|
138
|
-
export const normalizedCollRatio = (quote,
|
|
138
|
+
export const normalizedCollRatio = (quote, compoundedInterest, margin) => {
|
|
139
139
|
const amountIn = getAmountIn(quote).value;
|
|
140
140
|
const amountOut = getAmountOut(quote).value;
|
|
141
|
-
const interestNumerator =
|
|
142
|
-
const interestBase =
|
|
141
|
+
const interestNumerator = compoundedInterest.numerator.value;
|
|
142
|
+
const interestBase = compoundedInterest.denominator.value;
|
|
143
143
|
const numerator = multiply(
|
|
144
144
|
margin.numerator.value,
|
|
145
145
|
multiply(amountIn, interestNumerator),
|
|
@@ -159,17 +159,13 @@ 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} compoundedInterest
|
|
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
|
-
quote,
|
|
169
|
-
compoundedStabilityFee,
|
|
170
|
-
margin,
|
|
171
|
-
) => {
|
|
172
|
-
const collRatio = normalizedCollRatio(quote, compoundedStabilityFee, margin);
|
|
167
|
+
export const normalizedCollRatioKey = (quote, compoundedInterest, margin) => {
|
|
168
|
+
const collRatio = normalizedCollRatio(quote, compoundedInterest, margin);
|
|
173
169
|
return `${encodeNumber(collRatio)}:`;
|
|
174
170
|
};
|
|
175
171
|
harden(normalizedCollRatioKey);
|