@agoric/inter-protocol 0.13.2-dev-4e72872.0 → 0.13.2-dev-00d0eb1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/inter-protocol",
3
- "version": "0.13.2-dev-4e72872.0+4e72872",
3
+ "version": "0.13.2-dev-00d0eb1.0+00d0eb1",
4
4
  "description": "Core cryptoeconomy contracts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -29,28 +29,28 @@
29
29
  },
30
30
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
31
31
  "dependencies": {
32
- "@agoric/assert": "0.5.2-dev-4e72872.0+4e72872",
33
- "@agoric/ertp": "0.15.4-dev-4e72872.0+4e72872",
34
- "@agoric/governance": "0.9.2-dev-4e72872.0+4e72872",
35
- "@agoric/internal": "0.2.2-dev-4e72872.0+4e72872",
36
- "@agoric/notifier": "0.5.2-dev-4e72872.0+4e72872",
37
- "@agoric/store": "0.8.4-dev-4e72872.0+4e72872",
38
- "@agoric/time": "0.2.2-dev-4e72872.0+4e72872",
39
- "@agoric/vat-data": "0.4.4-dev-4e72872.0+4e72872",
40
- "@agoric/vats": "0.13.1-dev-4e72872.0+4e72872",
41
- "@agoric/zoe": "0.25.4-dev-4e72872.0+4e72872",
32
+ "@agoric/assert": "0.5.2-dev-00d0eb1.0+00d0eb1",
33
+ "@agoric/ertp": "0.15.4-dev-00d0eb1.0+00d0eb1",
34
+ "@agoric/governance": "0.9.2-dev-00d0eb1.0+00d0eb1",
35
+ "@agoric/internal": "0.2.2-dev-00d0eb1.0+00d0eb1",
36
+ "@agoric/notifier": "0.5.2-dev-00d0eb1.0+00d0eb1",
37
+ "@agoric/store": "0.8.4-dev-00d0eb1.0+00d0eb1",
38
+ "@agoric/time": "0.2.2-dev-00d0eb1.0+00d0eb1",
39
+ "@agoric/vat-data": "0.4.4-dev-00d0eb1.0+00d0eb1",
40
+ "@agoric/vats": "0.13.1-dev-00d0eb1.0+00d0eb1",
41
+ "@agoric/zoe": "0.25.4-dev-00d0eb1.0+00d0eb1",
42
42
  "@endo/captp": "^2.0.18",
43
43
  "@endo/eventual-send": "^0.16.8",
44
44
  "@endo/far": "^0.2.14",
45
45
  "@endo/marshal": "^0.8.1",
46
46
  "@endo/nat": "^4.1.23",
47
- "agoric": "0.18.3-dev-4e72872.0+4e72872"
47
+ "agoric": "0.18.3-dev-00d0eb1.0+00d0eb1"
48
48
  },
49
49
  "devDependencies": {
50
- "@agoric/deploy-script-support": "0.9.5-dev-4e72872.0+4e72872",
51
- "@agoric/smart-wallet": "0.4.3-dev-4e72872.0+4e72872",
52
- "@agoric/swingset-liveslots": "0.9.1-dev-4e72872.0+4e72872",
53
- "@agoric/swingset-vat": "0.30.3-dev-4e72872.0+4e72872",
50
+ "@agoric/deploy-script-support": "0.9.5-dev-00d0eb1.0+00d0eb1",
51
+ "@agoric/smart-wallet": "0.4.3-dev-00d0eb1.0+00d0eb1",
52
+ "@agoric/swingset-liveslots": "0.9.1-dev-00d0eb1.0+00d0eb1",
53
+ "@agoric/swingset-vat": "0.30.3-dev-00d0eb1.0+00d0eb1",
54
54
  "@endo/bundle-source": "^2.4.2",
55
55
  "@endo/init": "^0.5.52",
56
56
  "@endo/promise-kit": "^0.2.52",
@@ -76,5 +76,5 @@
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  },
79
- "gitHead": "4e72872a24071089e508f944629152a57c7f8bee"
79
+ "gitHead": "00d0eb1f984526f3771fa4c96e7829c8a80c06af"
80
80
  }
@@ -357,7 +357,7 @@ export const prepareAuctionBook = (baggage, zcf) => {
357
357
  * they request inconsistent limits.
358
358
  */
359
359
  addAssets(assetAmount, sourceSeat, proceedsGoal) {
360
- trace('add assets');
360
+ trace('add assets', { assetAmount, proceedsGoal });
361
361
  const { collateralBrand, collateralSeat, totalProceedsGoal } =
362
362
  this.state;
363
363
 
@@ -23,7 +23,7 @@ const { quote: q, Fail } = assert;
23
23
 
24
24
  const { StorageNodeShape } = makeTypeGuards(M);
25
25
 
26
- const trace = makeTracer('IV', false);
26
+ const trace = makeTracer('Vault', false);
27
27
 
28
28
  /** @typedef {import('./storeUtils.js').NormalizedDebt} NormalizedDebt */
29
29
 
@@ -86,7 +86,7 @@ const validTransitions = {
86
86
  /**
87
87
  * @typedef {object} VaultManager
88
88
  * @property {() => Subscriber<import('./vaultManager').AssetState>} getAssetSubscriber
89
- * @property {(collateralAmount: Amount) => ERef<Amount<'nat'>>} maxDebtFor
89
+ * @property {(collateralAmount: Amount) => Amount<'nat'>} maxDebtFor
90
90
  * @property {() => Brand} getCollateralBrand
91
91
  * @property {(base: string) => string} scopeDescription
92
92
  * @property {() => Brand<'nat'>} getDebtBrand
@@ -558,7 +558,7 @@ export const prepareVault = (baggage, marshaller, zcf) => {
558
558
  fp.want.Collateral,
559
559
  );
560
560
  // max debt supported by the vault Collateral implied by the proposal
561
- const maxDebtPre = await state.manager.maxDebtFor(newCollateralPre);
561
+ const maxDebtPre = state.manager.maxDebtFor(newCollateralPre);
562
562
  updaterPre === state.outerUpdater ||
563
563
  Fail`Transfer during vault adjustment`;
564
564
  helper.assertActive();
@@ -45,6 +45,7 @@ import { TransferPartShape } from '@agoric/zoe/src/contractSupport/atomicTransfe
45
45
  import {
46
46
  atomicRearrange,
47
47
  ceilMultiplyBy,
48
+ floorDivideBy,
48
49
  floorMultiplyBy,
49
50
  getAmountIn,
50
51
  getAmountOut,
@@ -54,15 +55,16 @@ import {
54
55
  offerTo,
55
56
  provideEmptySeat,
56
57
  } from '@agoric/zoe/src/contractSupport/index.js';
57
- import { SeatShape } from '@agoric/zoe/src/typeGuards.js';
58
+ import { PriceQuoteShape, SeatShape } from '@agoric/zoe/src/typeGuards.js';
58
59
  import { E } from '@endo/eventual-send';
59
60
  import { AuctionPFShape } from '../auction/auctioneer.js';
60
61
  import { checkDebtLimit, makeNatAmountShape } from '../contractSupport.js';
61
62
  import { chargeInterest } from '../interest.js';
62
63
  import { getLiquidatableVaults, liquidationResults } from './liquidation.js';
63
- import { maxDebtForVault } from './math.js';
64
+ import { calculateMinimumCollateralization } from './math.js';
64
65
  import { makePrioritizedVaults } from './prioritizedVaults.js';
65
66
  import { Phase, prepareVault } from './vault.js';
67
+ import { priceFrom } from '../auction/util.js';
66
68
 
67
69
  const { details: X, Fail } = assert;
68
70
 
@@ -199,11 +201,24 @@ export const prepareVaultManagerKit = (
199
201
  makeVaultManagerPublishKit();
200
202
  pipeTopicToStorage(metricsSubscriber, metricsNode, marshaller);
201
203
 
204
+ const quoteNotifier = E(priceAuthority).makeQuoteNotifier(
205
+ collateralUnit,
206
+ debtBrand,
207
+ );
202
208
  const storedQuotesNotifier = makeStoredNotifier(
203
- E(priceAuthority).makeQuoteNotifier(collateralUnit, debtBrand),
209
+ quoteNotifier,
204
210
  E(storageNode).makeChildNode('quotes'),
205
211
  marshaller,
206
212
  );
213
+ let storedCollateralQuote;
214
+ observeNotifier(quoteNotifier, {
215
+ updateState(value) {
216
+ storedCollateralQuote = value;
217
+ },
218
+ fail(reason) {
219
+ console.error('quoteNotifier failed to iterate', reason);
220
+ },
221
+ });
207
222
 
208
223
  const prioritizedVaults = makePrioritizedVaults(unsettledVaults);
209
224
 
@@ -284,7 +299,7 @@ export const prepareVaultManagerKit = (
284
299
  ),
285
300
  manager: M.interface('manager', {
286
301
  getGovernedParams: M.call().returns(M.remotable('governedParams')),
287
- maxDebtFor: M.call(AmountShape).returns(M.promise()),
302
+ maxDebtFor: M.call(AmountShape).returns(AmountShape),
288
303
  mintAndTransfer: M.call(
289
304
  SeatShape,
290
305
  AmountShape,
@@ -308,9 +323,9 @@ export const prepareVaultManagerKit = (
308
323
  self: M.interface('self', {
309
324
  getGovernedParams: M.call().returns(M.remotable('governedParams')),
310
325
  makeVaultKit: M.call(SeatShape).returns(M.promise()),
311
- getCollateralQuote: M.call().returns(M.promise()),
326
+ getCollateralQuote: M.call().returns(PriceQuoteShape),
312
327
  getPublicFacet: M.call().returns(M.remotable('publicFacet')),
313
- lockOraclePrices: M.call().returns(M.promise()),
328
+ lockOraclePrices: M.call().returns(PriceQuoteShape),
314
329
  liquidateVaults: M.call(AuctionPFShape).returns(M.promise()),
315
330
  }),
316
331
  },
@@ -821,22 +836,21 @@ export const prepareVaultManagerKit = (
821
836
  },
822
837
 
823
838
  /**
824
- * Consults a price authority to determine the max debt this manager
825
- * config will allow for the collateral.
839
+ * Look up the most recent price authority price to determine the max
840
+ * debt this manager config will allow for the collateral.
826
841
  *
827
842
  * @param {Amount<'nat'>} collateralAmount
828
843
  */
829
- async maxDebtFor(collateralAmount) {
830
- assert(factoryPowers && priceAuthority);
831
- const quote = await E(priceAuthority).quoteGiven(
832
- collateralAmount,
833
- debtBrand,
834
- );
835
- return maxDebtForVault(
836
- quote,
844
+ maxDebtFor(collateralAmount) {
845
+ assert(factoryPowers);
846
+ const collateralPrice = priceFrom(storedCollateralQuote);
847
+ const collatlVal = ceilMultiplyBy(collateralAmount, collateralPrice);
848
+ const minimumCollateralization = calculateMinimumCollateralization(
837
849
  factoryPowers.getGovernedParams().getLiquidationMargin(),
838
850
  factoryPowers.getGovernedParams().getLiquidationPadding(),
839
851
  );
852
+ // floorDivide because we want the debt ceiling lower
853
+ return floorDivideBy(collatlVal, minimumCollateralization);
840
854
  },
841
855
  /** @type {MintAndTransfer} */
842
856
  mintAndTransfer(mintReceiver, toMint, fee, transfers) {
@@ -1033,9 +1047,8 @@ export const prepareVaultManagerKit = (
1033
1047
  }
1034
1048
  },
1035
1049
 
1036
- async getCollateralQuote() {
1037
- // get a quote for one unit of the collateral
1038
- return E(priceAuthority).quoteGiven(collateralUnit, debtBrand);
1050
+ getCollateralQuote() {
1051
+ return storedCollateralQuote;
1039
1052
  },
1040
1053
 
1041
1054
  getPublicFacet() {
@@ -1043,17 +1056,15 @@ export const prepareVaultManagerKit = (
1043
1056
  },
1044
1057
 
1045
1058
  lockOraclePrices() {
1046
- const { state, facets } = this;
1047
- const { self } = facets;
1048
-
1049
- // XXX: 'twould be better if collateralQuote were updated lazily when it
1050
- // changes by more than X%, and we use a cached value. see #6946
1051
- return E.when(self.getCollateralQuote(), quote => {
1052
- trace(`lockPrice`, getAmountIn(quote), getAmountOut(quote));
1053
- // @ts-expect-error declared PriceQuote | undefined. TS thinks undefined.
1054
- state.lockedQuote = quote;
1055
- return quote;
1056
- });
1059
+ const { state } = this;
1060
+ trace(
1061
+ `lockPrice`,
1062
+ getAmountIn(storedCollateralQuote),
1063
+ getAmountOut(storedCollateralQuote),
1064
+ );
1065
+
1066
+ state.lockedQuote = storedCollateralQuote;
1067
+ return storedCollateralQuote;
1057
1068
  },
1058
1069
  /**
1059
1070
  * @param {AuctioneerPublicFacet} auctionPF
@@ -1062,7 +1073,7 @@ export const prepareVaultManagerKit = (
1062
1073
  const { state, facets } = this;
1063
1074
  const { self, helper } = facets;
1064
1075
  const { lockedQuote, compoundedInterest } = state;
1065
- const oraclePriceAtStartP = facets.self.getCollateralQuote();
1076
+ trace('considering liquidation');
1066
1077
 
1067
1078
  assert(factoryPowers && prioritizedVaults && zcf);
1068
1079
  lockedQuote ||
@@ -1113,17 +1124,13 @@ export const prepareVaultManagerKit = (
1113
1124
  // This is expected to wait for the duration of the auction, which
1114
1125
  // is controlled by the auction parameters startFrequency, clockStep,
1115
1126
  // and the difference between startingRate and lowestRate.
1116
- const [proceeds, oraclePrice] = await Promise.all([
1117
- deposited,
1118
- oraclePriceAtStartP,
1119
- userSeatPromise,
1120
- ]);
1127
+ const [proceeds] = await Promise.all([deposited, userSeatPromise]);
1121
1128
 
1122
1129
  trace(`LiqV after long wait`, proceeds);
1123
1130
  helper.distributeProceeds(
1124
1131
  proceeds,
1125
1132
  totalDebt,
1126
- oraclePrice,
1133
+ storedCollateralQuote,
1127
1134
  liqSeat,
1128
1135
  vaultData,
1129
1136
  totalCollateral,