@agoric/vats 0.15.2-dev-82d3548.0 → 0.15.2-dev-df3d0a7.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/vats",
3
- "version": "0.15.2-dev-82d3548.0+82d3548",
3
+ "version": "0.15.2-dev-df3d0a7.0+df3d0a7",
4
4
  "description": "Agoric's Vat library",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -22,18 +22,18 @@
22
22
  "author": "Agoric",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@agoric/assert": "0.6.1-dev-82d3548.0+82d3548",
26
- "@agoric/ertp": "0.16.3-dev-82d3548.0+82d3548",
27
- "@agoric/governance": "0.10.4-dev-82d3548.0+82d3548",
28
- "@agoric/internal": "0.3.3-dev-82d3548.0+82d3548",
29
- "@agoric/network": "0.1.1-dev-82d3548.0+82d3548",
30
- "@agoric/notifier": "0.6.3-dev-82d3548.0+82d3548",
31
- "@agoric/store": "0.9.3-dev-82d3548.0+82d3548",
32
- "@agoric/swingset-vat": "0.32.3-dev-82d3548.0+82d3548",
33
- "@agoric/time": "0.3.3-dev-82d3548.0+82d3548",
34
- "@agoric/vat-data": "0.5.3-dev-82d3548.0+82d3548",
35
- "@agoric/zoe": "0.26.3-dev-82d3548.0+82d3548",
36
- "@agoric/zone": "0.2.3-dev-82d3548.0+82d3548",
25
+ "@agoric/assert": "0.6.1-dev-df3d0a7.0+df3d0a7",
26
+ "@agoric/ertp": "0.16.3-dev-df3d0a7.0+df3d0a7",
27
+ "@agoric/governance": "0.10.4-dev-df3d0a7.0+df3d0a7",
28
+ "@agoric/internal": "0.3.3-dev-df3d0a7.0+df3d0a7",
29
+ "@agoric/network": "0.1.1-dev-df3d0a7.0+df3d0a7",
30
+ "@agoric/notifier": "0.6.3-dev-df3d0a7.0+df3d0a7",
31
+ "@agoric/store": "0.9.3-dev-df3d0a7.0+df3d0a7",
32
+ "@agoric/swingset-vat": "0.32.3-dev-df3d0a7.0+df3d0a7",
33
+ "@agoric/time": "0.3.3-dev-df3d0a7.0+df3d0a7",
34
+ "@agoric/vat-data": "0.5.3-dev-df3d0a7.0+df3d0a7",
35
+ "@agoric/zoe": "0.26.3-dev-df3d0a7.0+df3d0a7",
36
+ "@agoric/zone": "0.2.3-dev-df3d0a7.0+df3d0a7",
37
37
  "@endo/far": "^1.0.1",
38
38
  "@endo/import-bundle": "^1.0.1",
39
39
  "@endo/marshal": "^1.0.1",
@@ -44,7 +44,7 @@
44
44
  "jessie.js": "^0.3.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@agoric/swingset-liveslots": "0.10.3-dev-82d3548.0+82d3548",
47
+ "@agoric/swingset-liveslots": "0.10.3-dev-df3d0a7.0+df3d0a7",
48
48
  "@endo/bundle-source": "^3.0.1",
49
49
  "@endo/init": "^1.0.1",
50
50
  "ava": "^5.3.0",
@@ -78,5 +78,5 @@
78
78
  "typeCoverage": {
79
79
  "atLeast": 90.88
80
80
  },
81
- "gitHead": "82d35483fc88a1ec5c873ead92c215bba1372731"
81
+ "gitHead": "df3d0a78800845d0da9a3ebbe5841447c5bc61a6"
82
82
  }
@@ -348,7 +348,7 @@ type ChainBootstrapSpaceT = {
348
348
  pegasusConnectionsAdmin: import('@agoric/vats').NameAdmin;
349
349
  priceAuthorityVat: Awaited<PriceAuthorityVat>;
350
350
  priceAuthority: PriceAuthority;
351
- priceAuthorityAdmin: import('@agoric/zoe/tools/priceAuthorityRegistry').PriceAuthorityRegistryAdmin;
351
+ priceAuthorityAdmin: import('@agoric/vats/src/priceAuthorityRegistry').PriceAuthorityRegistryAdmin;
352
352
  provisioning: Awaited<ProvisioningVat> | undefined;
353
353
  provisionBridgeManager: import('../types.js').ScopedBridgeManager | undefined;
354
354
  provisionWalletBridgeManager:
@@ -0,0 +1,20 @@
1
+ export function providePriceAuthorityRegistry(baggage: import('@agoric/vat-data').Baggage): PriceAuthorityRegistry;
2
+ export type Deleter = {
3
+ delete: () => void;
4
+ };
5
+ export type PriceAuthorityRegistryAdmin = {
6
+ /**
7
+ * Add a unique price authority for a given pair
8
+ */
9
+ registerPriceAuthority: (pa: ERef<PriceAuthority>, brandIn: Brand, brandOut: Brand, force?: boolean) => Promise<Deleter>;
10
+ };
11
+ /**
12
+ * A price authority that is a facade
13
+ * for other backing price authorities registered for a given asset and price
14
+ * brand
15
+ */
16
+ export type PriceAuthorityRegistry = {
17
+ priceAuthority: PriceAuthority;
18
+ adminFacet: PriceAuthorityRegistryAdmin;
19
+ };
20
+ //# sourceMappingURL=priceAuthorityRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priceAuthorityRegistry.d.ts","sourceRoot":"","sources":["priceAuthorityRegistry.js"],"names":[],"mappings":"AA4CO,uDAHI,OAAO,kBAAkB,EAAE,OAAO,GAChC,sBAAsB,CA4KlC;;YAtMa,MAAM,IAAI;;;;;;iCAMf,KAAK,cAAc,CAAC,WACf,KAAK,YACJ,KAAK,UACP,OAAO,KACZ,QAAQ,OAAO,CAAC;;;;;;;;oBAQV,cAAc;gBACd,2BAA2B"}
@@ -0,0 +1,215 @@
1
+ import { BrandShape } from '@agoric/ertp';
2
+ import {
3
+ M,
4
+ prepareExo,
5
+ makeScalarBigMapStore,
6
+ provideDurableMapStore,
7
+ } from '@agoric/vat-data';
8
+ import { provideLazy } from '@agoric/store';
9
+ import { E } from '@endo/far';
10
+ import { Far } from '@endo/marshal';
11
+ import { PriceAuthorityI } from '@agoric/zoe/src/contractSupport/priceAuthority.js';
12
+
13
+ const { Fail } = assert;
14
+
15
+ /**
16
+ * @typedef {object} Deleter
17
+ * @property {() => void} delete
18
+ */
19
+
20
+ /**
21
+ * @typedef {object} PriceAuthorityRegistryAdmin
22
+ * @property {(
23
+ * pa: ERef<PriceAuthority>,
24
+ * brandIn: Brand,
25
+ * brandOut: Brand,
26
+ * force?: boolean,
27
+ * ) => Promise<Deleter>} registerPriceAuthority
28
+ * Add a unique price authority for a given pair
29
+ */
30
+
31
+ /**
32
+ * @typedef {object} PriceAuthorityRegistry A price authority that is a facade
33
+ * for other backing price authorities registered for a given asset and price
34
+ * brand
35
+ * @property {PriceAuthority} priceAuthority
36
+ * @property {PriceAuthorityRegistryAdmin} adminFacet
37
+ */
38
+
39
+ /**
40
+ * Make a singleton registry for priceAuthorities
41
+ *
42
+ * @param {import('@agoric/vat-data').Baggage} baggage
43
+ * @returns {PriceAuthorityRegistry}
44
+ */
45
+ export const providePriceAuthorityRegistry = baggage => {
46
+ /**
47
+ * @typedef {object} PriceAuthorityRecord A record indicating a registered
48
+ * price authority. We put a box around the priceAuthority to ensure the
49
+ * deleter doesn't delete the wrong thing.
50
+ * @property {ERef<PriceAuthority>} priceAuthority the sub-authority for a
51
+ * given input and output brand pair
52
+ */
53
+
54
+ /** @type {MapStore<Brand, MapStore<Brand, PriceAuthorityRecord>>} */
55
+ const assetToPriceStore = provideDurableMapStore(baggage, 'brandIn');
56
+
57
+ /**
58
+ * Get the registered price authority for a given input and output pair.
59
+ *
60
+ * @param {Brand} brandIn
61
+ * @param {Brand} brandOut
62
+ * @returns {ERef<PriceAuthority>}
63
+ */
64
+ const paFor = (brandIn, brandOut) => {
65
+ const priceStore = assetToPriceStore.get(brandIn);
66
+ return priceStore.get(brandOut).priceAuthority;
67
+ };
68
+
69
+ /**
70
+ * Create a quoteWhen* method for the given condition.
71
+ *
72
+ * @param {'LT' | 'LTE' | 'GTE' | 'GT'} relation
73
+ */
74
+ const makeQuoteWhen =
75
+ relation =>
76
+ /**
77
+ * Return a quote when relation is true of the arguments.
78
+ *
79
+ * @param {Amount<'nat'>} amountIn monitor the amountOut corresponding to
80
+ * this amountIn
81
+ * @param {Amount<'nat'>} amountOutLimit the value to compare with the
82
+ * monitored amountOut
83
+ * @returns {Promise<PriceQuote>} resolve with a quote when `amountOut
84
+ * relation amountOutLimit` is true
85
+ */
86
+ async (amountIn, amountOutLimit) => {
87
+ const pa = paFor(amountIn.brand, amountOutLimit.brand);
88
+ return E(pa)[`quoteWhen${relation}`](amountIn, amountOutLimit);
89
+ };
90
+
91
+ /**
92
+ * Create a mutableQuoteWhen* method for the given condition.
93
+ *
94
+ * @param {'LT' | 'LTE' | 'GTE' | 'GT'} relation
95
+ */
96
+ const makeMutableQuoteWhen =
97
+ relation =>
98
+ /**
99
+ * Return a mutable quote when relation is true of the arguments.
100
+ *
101
+ * @param {Amount} amountIn monitor the amountOut corresponding to this
102
+ * amountIn
103
+ * @param {Amount} amountOutLimit the value to compare with the monitored
104
+ * amountOut
105
+ * @returns {Promise<MutableQuote>} resolve with a quote when `amountOut
106
+ * relation amountOutLimit` is true
107
+ */
108
+ async (amountIn, amountOutLimit) => {
109
+ const pa = paFor(amountIn.brand, amountOutLimit.brand);
110
+ return E(pa)[`mutableQuoteWhen${relation}`](amountIn, amountOutLimit);
111
+ };
112
+
113
+ /**
114
+ * This PriceAuthority is just a wrapper for multiple registered
115
+ * PriceAuthorities.
116
+ *
117
+ * @type {PriceAuthority}
118
+ */
119
+ const priceAuthority = prepareExo(
120
+ baggage,
121
+ 'composite price authority',
122
+ PriceAuthorityI,
123
+ {
124
+ getQuoteIssuer(brandIn, brandOut) {
125
+ return E(paFor(brandIn, brandOut)).getQuoteIssuer(brandIn, brandOut);
126
+ },
127
+ getTimerService(brandIn, brandOut) {
128
+ return E(paFor(brandIn, brandOut)).getTimerService(brandIn, brandOut);
129
+ },
130
+ quoteGiven(amountIn, brandOut) {
131
+ return E(paFor(amountIn.brand, brandOut)).quoteGiven(
132
+ amountIn,
133
+ brandOut,
134
+ );
135
+ },
136
+ quoteWanted(brandIn, amountOut) {
137
+ return E(paFor(brandIn, amountOut.brand)).quoteWanted(
138
+ brandIn,
139
+ amountOut,
140
+ );
141
+ },
142
+ makeQuoteNotifier(amountIn, brandOut) {
143
+ return E(paFor(amountIn.brand, brandOut)).makeQuoteNotifier(
144
+ amountIn,
145
+ brandOut,
146
+ );
147
+ },
148
+ quoteAtTime(deadline, amountIn, brandOut) {
149
+ return E(paFor(amountIn.brand, brandOut)).quoteAtTime(
150
+ deadline,
151
+ amountIn,
152
+ brandOut,
153
+ );
154
+ },
155
+ quoteWhenLT: makeQuoteWhen('LT'),
156
+ quoteWhenLTE: makeQuoteWhen('LTE'),
157
+ quoteWhenGTE: makeQuoteWhen('GTE'),
158
+ quoteWhenGT: makeQuoteWhen('GT'),
159
+ mutableQuoteWhenLT: makeMutableQuoteWhen('LT'),
160
+ mutableQuoteWhenLTE: makeMutableQuoteWhen('LTE'),
161
+ mutableQuoteWhenGTE: makeMutableQuoteWhen('GTE'),
162
+ mutableQuoteWhenGT: makeMutableQuoteWhen('GT'),
163
+ },
164
+ );
165
+
166
+ /** @type {PriceAuthorityRegistryAdmin} */
167
+ const adminFacet = prepareExo(
168
+ baggage,
169
+ 'price authority admin facet',
170
+ M.interface('priceAuthorityRegistryAdmin', {
171
+ registerPriceAuthority: M.callWhen(
172
+ M.await(M.remotable('priceAuthority')),
173
+ BrandShape,
174
+ BrandShape,
175
+ )
176
+ .optional(M.boolean())
177
+ .returns(M.remotable('deleter')),
178
+ }),
179
+ {
180
+ registerPriceAuthority(pa, brandIn, brandOut, force = false) {
181
+ /** @type {MapStore<Brand, PriceAuthorityRecord>} */
182
+ const priceStore = provideLazy(assetToPriceStore, brandIn, () =>
183
+ makeScalarBigMapStore('brandOut', { durable: true }),
184
+ );
185
+
186
+ // Put a box around the authority so that we can be ensured the deleter
187
+ // won't delete the wrong thing.
188
+ const record = {
189
+ priceAuthority: pa,
190
+ };
191
+
192
+ // Set up the record.
193
+ if (force && priceStore.has(brandOut)) {
194
+ priceStore.set(brandOut, harden(record));
195
+ } else {
196
+ priceStore.init(brandOut, harden(record));
197
+ }
198
+
199
+ return Far('deleter', {
200
+ // @ts-expect-error XXX callWhen
201
+ delete() {
202
+ (priceStore.has(brandOut) && priceStore.get(brandOut) === record) ||
203
+ Fail`Price authority already dropped`;
204
+ priceStore.delete(brandOut);
205
+ },
206
+ });
207
+ },
208
+ },
209
+ );
210
+
211
+ return harden({
212
+ priceAuthority,
213
+ adminFacet,
214
+ });
215
+ };
@@ -7,8 +7,8 @@
7
7
  * @param {import('@agoric/vat-data').Baggage} baggage
8
8
  */
9
9
  export function buildRootObject(_vatPowers: VatPowers, _vatParams: unknown, baggage: import('@agoric/vat-data').Baggage): {
10
- getRegistry: () => import("@agoric/zoe/tools/priceAuthorityRegistry.js").PriceAuthorityRegistry;
10
+ getRegistry: () => import("./priceAuthorityRegistry.js").PriceAuthorityRegistry;
11
11
  } & import("@endo/eventual-send").RemotableBrand<{}, {
12
- getRegistry: () => import("@agoric/zoe/tools/priceAuthorityRegistry.js").PriceAuthorityRegistry;
12
+ getRegistry: () => import("./priceAuthorityRegistry.js").PriceAuthorityRegistry;
13
13
  }>;
14
14
  //# sourceMappingURL=vat-priceAuthority.d.ts.map
@@ -1,5 +1,5 @@
1
- import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js';
2
1
  import { Far } from '@endo/marshal';
2
+ import { providePriceAuthorityRegistry } from './priceAuthorityRegistry.js';
3
3
 
4
4
  /**
5
5
  * Vat holding the canonical PriceAuthorityRegistry for looking up prices on any