@agoric/inter-protocol 0.13.2-dev-02e99df.0 → 0.13.2-dev-ab7a341.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-02e99df.0+02e99df",
3
+ "version": "0.13.2-dev-ab7a341.0+ab7a341",
4
4
  "description": "Core cryptoeconomy contracts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -29,29 +29,29 @@
29
29
  },
30
30
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
31
31
  "dependencies": {
32
- "@agoric/assert": "0.5.2-dev-02e99df.0+02e99df",
33
- "@agoric/ertp": "0.15.4-dev-02e99df.0+02e99df",
34
- "@agoric/governance": "0.9.2-dev-02e99df.0+02e99df",
35
- "@agoric/internal": "0.2.2-dev-02e99df.0+02e99df",
36
- "@agoric/notifier": "0.5.2-dev-02e99df.0+02e99df",
37
- "@agoric/store": "0.8.4-dev-02e99df.0+02e99df",
38
- "@agoric/time": "0.2.2-dev-02e99df.0+02e99df",
39
- "@agoric/vat-data": "0.4.4-dev-02e99df.0+02e99df",
40
- "@agoric/vats": "0.13.1-dev-02e99df.0+02e99df",
41
- "@agoric/zoe": "0.25.4-dev-02e99df.0+02e99df",
32
+ "@agoric/assert": "0.5.2-dev-ab7a341.0+ab7a341",
33
+ "@agoric/ertp": "0.15.4-dev-ab7a341.0+ab7a341",
34
+ "@agoric/governance": "0.9.2-dev-ab7a341.0+ab7a341",
35
+ "@agoric/internal": "0.2.2-dev-ab7a341.0+ab7a341",
36
+ "@agoric/notifier": "0.5.2-dev-ab7a341.0+ab7a341",
37
+ "@agoric/store": "0.8.4-dev-ab7a341.0+ab7a341",
38
+ "@agoric/time": "0.2.2-dev-ab7a341.0+ab7a341",
39
+ "@agoric/vat-data": "0.4.4-dev-ab7a341.0+ab7a341",
40
+ "@agoric/vats": "0.13.1-dev-ab7a341.0+ab7a341",
41
+ "@agoric/zoe": "0.25.4-dev-ab7a341.0+ab7a341",
42
42
  "@endo/captp": "^3.1.1",
43
43
  "@endo/eventual-send": "^0.17.2",
44
44
  "@endo/far": "^0.2.18",
45
45
  "@endo/marshal": "^0.8.5",
46
46
  "@endo/nat": "^4.1.27",
47
- "agoric": "0.18.3-dev-02e99df.0+02e99df",
47
+ "agoric": "0.18.3-dev-ab7a341.0+ab7a341",
48
48
  "jessie.js": "^0.3.2"
49
49
  },
50
50
  "devDependencies": {
51
- "@agoric/deploy-script-support": "0.9.5-dev-02e99df.0+02e99df",
52
- "@agoric/smart-wallet": "0.4.3-dev-02e99df.0+02e99df",
53
- "@agoric/swingset-liveslots": "0.9.1-dev-02e99df.0+02e99df",
54
- "@agoric/swingset-vat": "0.30.3-dev-02e99df.0+02e99df",
51
+ "@agoric/deploy-script-support": "0.9.5-dev-ab7a341.0+ab7a341",
52
+ "@agoric/smart-wallet": "0.4.3-dev-ab7a341.0+ab7a341",
53
+ "@agoric/swingset-liveslots": "0.9.1-dev-ab7a341.0+ab7a341",
54
+ "@agoric/swingset-vat": "0.30.3-dev-ab7a341.0+ab7a341",
55
55
  "@endo/bundle-source": "^2.5.1",
56
56
  "@endo/init": "^0.5.56",
57
57
  "@endo/promise-kit": "^0.2.56",
@@ -77,5 +77,5 @@
77
77
  "publishConfig": {
78
78
  "access": "public"
79
79
  },
80
- "gitHead": "02e99df0d4ef3709c2c413cbcb10cd6779a28036"
80
+ "gitHead": "ab7a341a734f6a7c951819e528defc0d6b527c50"
81
81
  }
@@ -27,7 +27,6 @@ const BASIS_POINTS = 10_000n;
27
27
  /**
28
28
  * @typedef {GovernedCreatorFacet<import('../stakeFactory/stakeFactory.js').StakeFactoryCreator>} StakeFactoryCreator
29
29
  * @typedef {import('../stakeFactory/stakeFactory.js').StakeFactoryPublic} StakeFactoryPublic
30
- * @typedef {import('../reserve/assetReserve.js').GovernedAssetReserveFacetAccess} GovernedAssetReserveFacetAccess
31
30
  * @typedef {import('../vaultFactory/vaultFactory.js').VaultFactoryContract['publicFacet']} VaultFactoryPublicFacet
32
31
  * @typedef {import('../auction/auctioneer.js').AuctioneerPublicFacet} AuctioneerPublicFacet
33
32
  * @typedef {import('../auction/auctioneer.js').AuctioneerCreatorFacet} AuctioneerCreatorFacet
@@ -63,7 +62,7 @@ const BASIS_POINTS = 10_000n;
63
62
  * psmKit: MapStore<Brand, PSMKit>,
64
63
  * anchorBalancePayments: MapStore<Brand, Payment<'nat'>>,
65
64
  * econCharterKit: EconCharterStartResult,
66
- * reserveKit: GovernanceFacetKit<import('../reserve/assetReserve.js')['start']>,
65
+ * reserveKit: GovernanceFacetKit<import('../reserve/assetReserve.js')['prepare']>,
67
66
  * stakeFactoryKit: GovernanceFacetKit<import('../stakeFactory/stakeFactory.js')['start']>,
68
67
  * vaultFactoryKit: GovernanceFacetKit<import('../vaultFactory/vaultFactory.js')['prepare']>,
69
68
  * auctioneerKit: AuctioneerKit,
@@ -1,27 +1,14 @@
1
1
  // @jessie-check
2
2
 
3
- import { E, Far } from '@endo/far';
4
- import { AmountMath } from '@agoric/ertp';
5
3
  import { handleParamGovernance } from '@agoric/governance';
6
- import { atomicTransfer } from '@agoric/zoe/src/contractSupport/index.js';
7
- import { provideDurableMapStore, prepareKindMulti } from '@agoric/vat-data';
8
4
  import { makeTracer } from '@agoric/internal';
5
+ import {
6
+ prepareRecorderKitMakers,
7
+ provideAll,
8
+ } from '@agoric/zoe/src/contractSupport/index.js';
9
+ import { prepareAssetReserveKit } from './assetReserveKit.js';
9
10
 
10
- import { makeMetricsPublisherKit } from '../contractSupport.js';
11
-
12
- const { Fail, quote: q } = assert;
13
-
14
- const trace = makeTracer('Reserve', false);
15
-
16
- /**
17
- * @typedef {object} MetricsNotification
18
- *
19
- * @property {AmountKeywordRecord} allocations
20
- * @property {Amount<'nat'>} shortfallBalance shortfall from liquidation that
21
- * has not yet been compensated.
22
- * @property {Amount<'nat'>} totalFeeMinted total Fee tokens minted to date
23
- * @property {Amount<'nat'>} totalFeeBurned total Fee tokens burned to date
24
- */
11
+ const trace = makeTracer('AR', false);
25
12
 
26
13
  /**
27
14
  * @typedef {{
@@ -30,22 +17,6 @@ const trace = makeTracer('Reserve', false);
30
17
  * }} ShortfallReportingFacet
31
18
  */
32
19
 
33
- /**
34
- * @typedef {{
35
- * state: {
36
- * totalFeeBurned: Amount<'nat'>,
37
- * totalFeeMinted: Amount<'nat'>,
38
- * },
39
- * facets: {
40
- * publicFacet: {},
41
- * creatorFacet: {},
42
- * shortfallReportingFacet: ShortfallReportingFacet,
43
- * limitedCreatorFacet: {},
44
- * governedApis: {},
45
- * },
46
- * }} MethodContext
47
- */
48
-
49
20
  /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
50
21
 
51
22
  /**
@@ -68,24 +39,17 @@ const trace = makeTracer('Reserve', false);
68
39
  * }} privateArgs
69
40
  * @param {Baggage} baggage
70
41
  */
71
- const start = async (zcf, privateArgs, baggage) => {
42
+ export const prepare = async (zcf, privateArgs, baggage) => {
43
+ trace('prepare', Object.keys(privateArgs), [...baggage.keys()]);
72
44
  // This contract mixes two styles of access to durable state. durableStores
73
45
  // are declared at the top level and referenced lexically. local state is
74
46
  // accessed via the `state` object. The latter means updates are made directly
75
47
  // to state and don't require reference to baggage.
76
48
 
77
- /**
78
- * Used to look up the unique keyword for each brand, including Fee brand.
79
- *
80
- * @type {MapStore<Brand, Keyword>}
81
- */
82
- const keywordForBrand = provideDurableMapStore(baggage, 'keywordForBrand');
83
- /**
84
- * Used to look up the brands for keywords, excluding Fee because it's a special case.
85
- *
86
- * @type {MapStore<Keyword, Brand>}
87
- */
88
- const brandForKeyword = provideDurableMapStore(baggage, 'brandForKeyword');
49
+ const { makeRecorderKit } = prepareRecorderKitMakers(
50
+ baggage,
51
+ privateArgs.marshaller,
52
+ );
89
53
 
90
54
  /** @type {() => Promise<ZCFMint<'nat'>>} */
91
55
  const takeFeeMint = async () => {
@@ -100,214 +64,49 @@ const start = async (zcf, privateArgs, baggage) => {
100
64
  baggage.init('feeMint', feeMintTemp);
101
65
  return feeMintTemp;
102
66
  };
67
+ trace('awaiting takeFeeMint');
103
68
  const feeMint = await takeFeeMint();
104
- const feeKit = feeMint.getIssuerRecord();
105
- const emptyAmount = AmountMath.makeEmpty(feeKit.brand);
106
-
107
- /**
108
- * @param {Brand} brand
109
- * @param {Keyword} keyword
110
- */
111
- const saveBrandKeyword = (brand, keyword) => {
112
- keywordForBrand.init(brand, keyword);
113
- brandForKeyword.init(keyword, brand);
114
- };
115
-
116
- saveBrandKeyword(feeKit.brand, 'Fee');
117
- // no need to saveIssuer() b/c registerFeeMint did it
118
-
119
- const { augmentVirtualPublicFacet, makeVirtualGovernorFacet } =
120
- await handleParamGovernance(
121
- zcf,
122
- privateArgs.initialPoserInvitation,
123
- {},
124
- privateArgs.storageNode,
125
- privateArgs.marshaller,
126
- );
127
-
128
- /**
129
- * @param {MethodContext} _context
130
- * @param {Issuer} issuer
131
- * @param {string} keyword
132
- */
133
- const addIssuer = async (_context, issuer, keyword) => {
134
- const brand = await E(issuer).getBrand();
135
- trace('addIssuer', { brand, keyword });
136
- assert(
137
- keyword !== 'Fee' && brand !== feeKit.brand,
138
- `'Fee' brand is a special case handled by the reserve contract`,
139
- );
140
-
141
- trace('addIssuer storing', {
142
- keyword,
143
- brand,
144
- });
145
-
146
- saveBrandKeyword(brand, keyword);
147
- await zcf.saveIssuer(issuer, keyword);
148
- };
149
-
150
- const getKeywordForBrand = brand => {
151
- keywordForBrand.has(brand) ||
152
- Fail`Issuer not defined for brand ${q(brand)}; first call addIssuer()`;
153
- return keywordForBrand.get(brand);
154
- };
155
-
156
- // We keep the associated liquidity tokens in the same seat
157
- const { zcfSeat: collateralSeat } = zcf.makeEmptySeatKit();
158
- const getAllocations = () => {
159
- return collateralSeat.getCurrentAllocation();
160
- };
161
-
162
- /**
163
- * Anyone can deposit any assets to the reserve
164
- *
165
- * @param {*} state
166
- */
167
- const addCollateralHook = state => async (/** @type {ZCFSeat} */ seat) => {
168
- const {
169
- give: { Collateral: amountIn },
170
- } = seat.getProposal();
171
-
172
- const collateralKeyword = getKeywordForBrand(amountIn.brand);
173
-
174
- atomicTransfer(
175
- zcf,
176
- seat,
177
- collateralSeat,
178
- { Collateral: amountIn },
179
- { [collateralKeyword]: amountIn },
180
- );
181
- seat.exit();
182
- // eslint-disable-next-line no-use-before-define
183
- updateMetrics({ state });
184
-
185
- trace('received collateral', amountIn);
186
- return 'added Collateral to the Reserve';
187
- };
69
+ const makeAssetReserveKit = await prepareAssetReserveKit(baggage, {
70
+ feeMint,
71
+ makeRecorderKit,
72
+ // eslint-disable-next-line @jessie.js/no-nested-await -- spurious
73
+ storageNode: await privateArgs.storageNode,
74
+ zcf,
75
+ });
188
76
 
189
- const makeAddCollateralInvitation = ({ state }) =>
190
- zcf.makeInvitation(addCollateralHook(state), 'Add Collateral');
77
+ const { assetReserveKit } = await provideAll(baggage, {
78
+ assetReserveKit: makeAssetReserveKit,
79
+ });
191
80
 
192
- /** @type {import('../contractSupport.js').MetricsPublisherKit<MetricsNotification>} */
193
- const { metricsPublication, metricsSubscription } = makeMetricsPublisherKit(
81
+ trace('awaiting handleParamGovernance');
82
+ const { makeDurableGovernorFacet } = await handleParamGovernance(
83
+ zcf,
84
+ privateArgs.initialPoserInvitation,
85
+ {},
194
86
  privateArgs.storageNode,
195
87
  privateArgs.marshaller,
196
88
  );
197
89
 
198
- const updateMetrics = ({ state }) => {
199
- const metrics = harden({
200
- allocations: getAllocations(),
201
- shortfallBalance: state.shortfallBalance,
202
- totalFeeMinted: state.totalFeeMinted,
203
- totalFeeBurned: state.totalFeeBurned,
204
- });
205
- metricsPublication.updateState(metrics);
206
- };
207
-
208
- const increaseLiquidationShortfall = ({ state }, shortfall) => {
209
- state.shortfallBalance = AmountMath.add(state.shortfallBalance, shortfall);
210
- updateMetrics({ state });
211
- };
212
-
213
- const reduceLiquidationShortfall = ({ state }, reduction) => {
214
- if (AmountMath.isGTE(reduction, state.shortfallBalance)) {
215
- state.shortfallBalance = emptyAmount;
216
- } else {
217
- state.shortfallBalance = AmountMath.subtract(
218
- state.shortfallBalance,
219
- reduction,
220
- );
221
- }
222
- updateMetrics({ state });
223
- };
224
-
225
- const init = () => {
226
- const initialState = {
227
- totalFeeMinted: emptyAmount,
228
- totalFeeBurned: emptyAmount,
229
- shortfallBalance: emptyAmount,
230
- };
231
- updateMetrics({ state: initialState });
232
- return initialState;
233
- };
234
-
235
- /**
236
- *
237
- * @param {MethodContext} context
238
- * @param {Amount<'nat'>} reduction
239
- * @returns {void}
240
- */
241
- const burnFeesToReduceShortfall = ({ state }, reduction) => {
242
- trace('burnFeesToReduceShortfall', reduction);
243
- reduction = AmountMath.coerce(feeKit.brand, reduction);
244
- const feeKeyword = keywordForBrand.get(feeKit.brand);
245
- const feeBalance = collateralSeat.getAmountAllocated(feeKeyword);
246
- const amountToBurn = AmountMath.min(reduction, feeBalance);
247
- if (AmountMath.isEmpty(amountToBurn)) {
248
- return;
249
- }
250
-
251
- feeMint.burnLosses(harden({ [feeKeyword]: amountToBurn }), collateralSeat);
252
- state.totalFeeBurned = AmountMath.add(state.totalFeeBurned, amountToBurn);
253
- updateMetrics({ state });
254
- };
255
-
256
- const shortfallReportingFacet = {
257
- increaseLiquidationShortfall,
258
- // currently exposed for testing. Maybe it only gets called internally?
259
- reduceLiquidationShortfall,
260
- };
261
-
262
- /** @param {MethodContext} context */
263
- const makeShortfallReportingInvitation = ({ facets }) => {
264
- const handleShortfallReportingOffer = () => {
265
- return facets.shortfallReportingFacet;
266
- };
267
-
268
- return zcf.makeInvitation(
269
- handleShortfallReportingOffer,
270
- 'getFacetForReportingShortfalls',
271
- );
272
- };
273
-
274
- const { governorFacet, limitedCreatorFacet } = makeVirtualGovernorFacet({
275
- makeAddCollateralInvitation,
276
- // add makeRedeemLiquidityTokensInvitation later. For now just store them
277
- getAllocations,
278
- addIssuer,
279
- makeShortfallReportingInvitation,
280
- getMetrics: () => metricsSubscription,
281
- });
282
-
283
- const governedApis = { burnFeesToReduceShortfall };
284
-
285
- const publicFacet = augmentVirtualPublicFacet(
286
- Far('Collateral Reserve public', {
287
- makeAddCollateralInvitation,
288
- }),
90
+ const { governorFacet } = makeDurableGovernorFacet(
91
+ baggage,
92
+ assetReserveKit.machine,
93
+ // reconstruct facet so that the keys are enumerable and that the client can't depend on object identity
94
+ {
95
+ burnFeesToReduceShortfall: reduction =>
96
+ assetReserveKit.governedApis.burnFeesToReduceShortfall(reduction),
97
+ },
289
98
  );
290
99
 
291
- const makeAssetReserve = prepareKindMulti(baggage, 'assetReserve', init, {
292
- publicFacet,
293
- creatorFacet: governorFacet,
294
- shortfallReportingFacet,
295
- limitedCreatorFacet,
296
- governedApis,
297
- });
298
-
299
- const { creatorFacet, publicFacet: pFacet } = makeAssetReserve();
300
100
  return {
301
- /** @type {GovernedCreatorFacet<OriginalAssetReserveCreatorFacet>} */
302
- // @ts-expect-error cast
303
- creatorFacet,
304
- publicFacet: pFacet,
101
+ /** @type {GovernedCreatorFacet<typeof assetReserveKit.machine>} */
102
+ creatorFacet: governorFacet,
103
+ /** @type {GovernedPublicFacet<typeof assetReserveKit.public>} */
104
+ // cast due to missing governance mixins
105
+ // XXX https://github.com/Agoric/agoric-sdk/issues/5200
106
+ publicFacet: /** @type {any} */ (assetReserveKit.public),
305
107
  };
306
108
  };
307
-
308
- harden(start);
309
-
310
- export { start };
109
+ harden(prepare);
311
110
 
312
111
  /**
313
112
  * @typedef {object} ShortfallReporter
@@ -316,20 +115,11 @@ export { start };
316
115
  */
317
116
 
318
117
  /**
319
- * @typedef {object} OriginalAssetReserveCreatorFacet
320
- * @property {() => Invitation} makeAddCollateralInvitation
321
- * @property {() => Allocation} getAllocations
118
+ * @typedef {object} AssetReserveLimitedCreatorFacet
322
119
  * @property {(issuer: Issuer, kwd: string) => void} addIssuer
323
- * @property {() => Invitation<ShortfallReporter>} makeShortfallReportingInvitation
324
- * @property {() => StoredSubscription<MetricsNotification>} getMetrics
325
- */
326
-
327
- /**
328
- * @typedef {object} OriginalAssetReservePublicFacet
329
- * @property {() => Invitation} makeAddCollateralInvitation
120
+ * @property {() => Allocation} getAllocations
121
+ * @property {() => Promise<Invitation<ShortfallReporter>>} makeShortfallReportingInvitation
330
122
  */
331
123
 
332
- /** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} AssetReservePublicFacet */
333
- /** @typedef {Awaited<ReturnType<typeof start>>['creatorFacet']} AssetReserveCreatorFacet the creator facet for the governor */
334
- /** @typedef {OriginalAssetReserveCreatorFacet} AssetReserveLimitedCreatorFacet */
335
- /** @typedef {GovernorCreatorFacet<typeof start>} GovernedAssetReserveFacetAccess */
124
+ /** @typedef {Awaited<ReturnType<typeof prepare>>['publicFacet']} AssetReservePublicFacet */
125
+ /** @typedef {Awaited<ReturnType<typeof prepare>>['creatorFacet']} AssetReserveCreatorFacet the creator facet for the governor */